How to select the reserved word (limit) in postgres

爷,独闯天下 提交于 2020-04-18 12:56:14

问题


I have the field 'limit' in a table in my postgres database. I run psql and I can't select, update, change this field because is a reserved word in postgresql. There is a way to manage this field?

serene-retreat::SILVER=> select limit from companies;
ERROR:  syntax error at or near "limit"
LINE 1: select limit from companies;

回答1:


In SQL reserved (key)words need to be quoted using double quotes:

select "limit" 
from companies;

Note that this also makes column case-sensitive: "LIMIT" is a different name than "limit".

This all explained in the manual:
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS




回答2:


use this

select [limit] from companies;

or

select companies.[limit] from companies;


来源:https://stackoverflow.com/questions/29053168/how-to-select-the-reserved-word-limit-in-postgres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!