【问题标题】:How to add a string literal as one selected column for select queries?如何将字符串文字添加为选择查询的一个选定列?
【发布时间】:2020-01-02 08:54:42
【问题描述】:

我想要如下查询

select "RETRY" as code , name from process ;

那么结果是

code |  name
_____________

RETRY  PX1
RETRY  PX1
RETRY  PX3
RETRY  PX4
RETRY  PX5

我想为选择查询返回的所有行添加一个字符串文字作为列。我在 PostgreSQL 中尝试这样做,但收到以下错误:

SQL Error [42703]: ERROR: column "RETRY" does not exist
  Position: 8

你知道如何在 PostgreSQL 选择查询中执行此操作吗?

【问题讨论】:

    标签: sql postgresql string-constant


    【解决方案1】:

    双引号是指该表的列名,这就是为什么你得到错误你必须使用单引号

    select 'RETRY' as code , name from process ;
    

    【讨论】:

    • 是的,单引号有效,感谢您的帮助。
    【解决方案2】:

    字符串字面量需要在 SQL 中用单引号 enclosed

    select 'RETRY' as code, name 
    from process;
    

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      相关资源
      最近更新 更多