我正在使用一个框架 (Jodd),它将表别名添加到 SQL Select 中的列名称。它看起来像格式良好的 SQL,但 Postgres 对此感到窒息。
update GREETING Greeting
set Greeting.ID=5,
Greeting.NAME='World',
Greeting.PHRASE='Hello World!'
where (Greeting.ID=5)
报错:
Error: ERROR: column "greeting" of relation "greeting" does not exist
SQLState: 42703
有没有办法让 Postgres 接受那个 SQL?我的另一个选择是破解框架,我不想这样做。
最佳答案
问题是您在 SET
子句中的列中包含了表别名。请参阅 UPDATE
in Postgres docs 的文档:
column
The name of a column in
table
. The column name can be qualified with a subfield name or array subscript, if needed. Do not include the table's name in the specification of a target column — for example,UPDATE tab SET tab.col = 1
is invalid.
这在 Postgres 中有效:
update GREETING Greeting
set
NAME='World',
PHRASE='Hello World!'
where Greeting.ID=5 ;
关于sql - Postgres 不接受列名前的表别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11369757/