如何添加字符串文字作为选择查询的一个选定列?

Bra*_*avo 10 sql postgresql string-constant

我想要像下面这样的查询

select "RETRY" as code , name from process ;
Run Code Online (Sandbox Code Playgroud)

那么结果是

code |  name
_____________

RETRY  PX1
RETRY  PX1
RETRY  PX3
RETRY  PX4
RETRY  PX5
Run Code Online (Sandbox Code Playgroud)

我想为选择查询返回的所有行添加一个字符串文字作为列。我正在 PostgreSQL 中尝试此操作,但出现以下错误:

SQL Error [42703]: ERROR: column "RETRY" does not exist
  Position: 8
Run Code Online (Sandbox Code Playgroud)

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

Zay*_*hin 7

双引号引用该表的列名,这就是您收到错误的原因,您必须使用单引号

select 'RETRY' as code , name from process ;
Run Code Online (Sandbox Code Playgroud)