SQLite 中字符串字面量和标识符的区别 [英] Difference between String Literal and Identifier in SQLite
问题描述
字符串文字和标识符有什么区别?我试着用谷歌搜索这个,结果更困惑
What's the difference between a string literal and an identifier? I tried googling this and ended up being more confused
对 Python 的差异和 SQLite 的差异特别感兴趣
Specifically interested with the difference in Python, and difference in SQLite
来自 SQLite 文档
From SQLite Documentation
'keyword' A keyword in single quotes is a string literal.
"keyword" A keyword in double-quotes is an identifier.
参考文档https://docs.python.org/3/reference/lexical_analysis.html#identifiershttps://www.sqlite.org/lang_keywords.html
推荐答案
标识符是一个变量名.在以下 python 行中
An identifier is a variable name. In the following python line
foo = "bar"
foo
是一个标识符,bar"是一个标识符.是字符串文字.在 Python 中,字符串文字可以用简单的 ('
') 或双引号 ("
) 括起来.
foo
is an identifier and "bar" is a string literal. In Python, string literal can be enclosed in simple ('
') or double ("
) quotes.
在 SQLite 中(更普遍的是在 SQL 中),字符串文字用单引号括起来.双引号用于强制将包含特殊字符的字符串解释为标识符.
In SQLite (and more generally in SQL), string literals are enclosed in single quotes. Double quotes are use to force a string containing otherwise special characters to be interpreted as identifiers.
假设表 foo
与列 bar
的示例:
Example assuming a table foo
with column bar
:
SELECT bar as "Bar", 'zz' as OTHER from foo;
在此选择中,第一列的名称为 Bar
.如果没有 "
,名称将是 bar
,因为 SQL 通常不区分大小写.第二列是常量 zz
,列名是 other
.
In this select, the first column will have name Bar
. Without the "
, the name would have been bar
since SQL does not normally distinguishes case. The second column will the the constant zz
and the column name will be other
.
对于非英语语言,"
也可用于具有重音字符,例如 éè
.
The "
are also useful to have accented chars like éè
for non english languages.
这篇关于SQLite 中字符串字面量和标识符的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!