【问题标题】:How to select the reserved word (limit) in postgrespostgres中如何选择保留字(limit)
【发布时间】:2015-03-14 19:21:08
【问题描述】:

我的 postgres 数据库的表中有字段“限制”。我运行 psql 并且无法选择、更新、更改此字段,因为它是 postgresql 中的保留字。有办法管理这个字段吗?

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

【问题讨论】:

    标签: database postgresql-9.1


    【解决方案1】:

    在 SQL 中保留(关键字)字需要用双引号引起来:

    select "limit" 
    from companies;
    

    请注意,这也会使列区分大小写:"LIMIT""limit" 的名称不同。

    这一切在手册中都有解释:
    http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

    【讨论】:

      【解决方案2】:

      使用这个

      select [limit] from companies;
      

      select companies.[limit] from companies;
      

      【讨论】:

      • 这个也可以试试... select 'limit' from Companies;
      • 我不明白你最后的建议
      • 它列出了单词'limit'并且没有值并且标题说'?column?'
      • 这在“SQL”中不起作用。 SQL 标准非常明确:保留字需要用双引号括起来。对于标识符,方括号在“SQL”(标准查询语言)中完全无效
      猜你喜欢
      • 1970-01-01
      • 2014-09-17
      • 2011-01-24
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 2013-05-03
      相关资源
      最近更新 更多