When do Postgres column or table names need quotes and when don't they?

后端 未结 2 1974
粉色の甜心
粉色の甜心 2020-12-01 20:05

Let\'s consider the following postgres query:

SELECT * 
FROM \"MY_TABLE\"
WHERE \"bool_var\"=FALSE 
 AND \"str_var\"=\'something\';

The que

2条回答
  •  长情又很酷
    2020-12-01 20:50

    Thanks to @TimBiegeleisen's comment, I was able to pinpoint the problem; I used a reserved keyword ("user") as a column name.

    Link to reserved keywords in the doc: https://www.postgresql.org/docs/current/sql-keywords-appendix.html.

    Now I know not to use quotes to query column names, but rather to avoid reserved keywords as column names.

提交回复
热议问题