如果Postgres表中的列的名称为year,应如何查看INSERT查询以设置该列的值?
If the column in Postgres' table has the name year, how should look INSERT query to set the value for that column?
例如:INSERT INTO table (id, name, year) VALUES ( ... );在 year 单词附近给出错误.
E.g.: INSERT INTO table (id, name, year) VALUES ( ... ); gives an error near the year word.
推荐答案只需将year用双引号引起来,以防止将其解释为关键字:
Simply enclose year in double quotes to stop it being interpreted as a keyword:
INSERT INTO table (id, name, "year") VALUES ( ... );从文档:
还有第二种标识符:带分隔符的标识符或 带引号的标识符.它是通过包含任意顺序的 双引号()中的字符.带分隔符的标识符始终是 标识符,而不是关键字.因此,选择"可用于指代 列或表名为选择",而未引用的选择将是 用作关键字,因此在以下情况时会引发解析错误: 用于需要表名或列名的地方.
There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). A delimited identifier is always an identifier, never a key word. So "select" could be used to refer to a column or table named "select", whereas an unquoted select would be taken as a key word and would therefore provoke a parse error when used where a table or column name is expected.
更多推荐
在Postgres中转义类似关键字的列名
发布评论