简体   繁体   English

奇数没有这样的列错误SQLite3

[英]Odd no such column error SQLite3

I'm only beginning to learn SQL with SQLite3 so this question probably has a clear answer, which I just can't think of. 我才刚刚开始使用SQLite3学习SQL,所以这个问题可能有一个明确的答案,我只是想不到。 I have a table called Books, which has the columns: name, author and price. 我有一个名为Books的表,该表具有以下列:名称,作者和价格。 When I type eg select name, price from Books where author = "A"; 当我输入例如select name, price from Books where author = "A";输入select name, price from Books where author = "A"; in sqlite3, it works just fine. 在sqlite3中,它可以正常工作。 However, when I make a .sql file with the following: 但是,当我使用以下命令制作.sql文件时:

 SELECT name, price
 FROM Books
 WHERE author = "A";`

and read the file in the same database, it reads 并在同一数据库中读取文件,它读取

 'Error: near line 1: no such column: "A"'

Any ideas? 有任何想法吗?

Edit: I have also tried the same with single quotes (ie 'A') but it still gives the same error: 编辑:我也尝试过用单引号(即'A')相同,但它仍然给出相同的错误:

Error: near line 1: no such column: 'A'

Double quotes "A" are used as identifiers; 双引号"A"用作标识符; you want to use single quotes 'A' for string literals. 您想对字符串文字使用单引号'A' See the documentation for more information. 请参阅文档以获取更多信息。

SELECT name, price FROM Books WHERE author = 'A' ; SELECT name, price FROM Books WHERE author = 'A'

The reason it worked in the first example is probably due to this: 它在第一个示例中起作用的原因可能是由于以下原因:

If a keyword in double quotes (ex: "key" or "glob") is used in a context where it cannot be resolved to an identifier but where a string literal is allowed, then the token is understood to be a string literal instead of an identifier. 如果在无法将其解析为标识符但允许使用字符串文字的情况下使用双引号引起来的关键字(例如:“ key”或“ glob”),则该令牌应理解为字符串文字,而不是标识符。

I found the solution. 我找到了解决方案。 I was using Mac's TextEdit program to write the SQL queries and it uses so called "smart quotes", which are not recognized as quotes by SQL. 我使用Mac的TextEdit程序编写SQL查询,它使用了所谓的“智能引号”,SQL无法将其识别为引号。 So I just changed the smart quote-setting off and all is well. 所以我只是更改了智能报价设置,一切都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM