1

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;
Papaya Labs
  • 1,079
  • 9
  • 11

2 Answers2

5

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

0

use this

select [limit] from companies;

or

select companies.[limit] from companies;
Faisal Hameed
  • 104
  • 1
  • 9
  • this can also be tried... select '`limit`' from companies; – Faisal Hameed Mar 14 '15 at 19:32
  • I dont understand your last suggestion – Papaya Labs Mar 14 '15 at 19:34
  • It list the word 'limit' and no values and the header say '?column?' – Papaya Labs Mar 14 '15 at 19:38
  • That does not work "in SQL". The SQL standard is pretty clear: reserved words need to be enclosed in double quotes. Square brackets are completely invalid "in SQL" (the standard query language) for an identifier –  Mar 14 '15 at 19:54
  • check this link http://stackoverflow.com/questions/285775/how-to-deal-with-sql-column-names-that-look-like-sql-keywords – Faisal Hameed Mar 14 '15 at 19:57
  • That's for *SQL **Server*** not for "SQL". (you _can_ actually make SQL Server honour the SQL standard and accept double quotes for quoted identifiers) –  Mar 14 '15 at 20:17