SQLite 中字符串文字和标识符的区别

can*_*289 2 python sqlite

字符串文字和标识符有什么区别?我尝试用谷歌搜索这个结果却变得更加困惑

特别对 Python 中的差异和 SQLite 中的差异感兴趣

来自 SQLite 文档

'keyword'       A keyword in single quotes is a string literal.
"keyword"       A keyword in double-quotes is an identifier.
Run Code Online (Sandbox Code Playgroud)

参考文档 https://docs.python.org/3/reference/lexical_analysis.html#identifiers https://www.sqlite.org/lang_keywords.html

Ser*_*sta 5

标识符是变量名。在下面的Python行中

\n
foo = "bar"\n
Run Code Online (Sandbox Code Playgroud)\n

foo是一个标识符,“bar”是一个字符串文字。'在 Python 中,字符串文字可以用单引号 ( ') 或双引号 ( )括起来"

\n

在 SQLite(更常见的是 SQL)中,字符串文字用单引号括起来。双引号用于强制将包含其他特殊字符的字符串解释为标识符。

\n

假设一个foo包含列的表的示例bar

\n
SELECT bar as "Bar", 'zz' as OTHER from foo;\n
Run Code Online (Sandbox Code Playgroud)\n

在此选择中,第一列将具有 name Bar。如果没有",该名称将是,bar因为 SQL 通常不区分大小写。第二列将是常量zz,列名称将是other

\n

对于非英语语言"等带有重音字符的字符也很有用。\xc3\xa9\xc3\xa8

\n