【问题标题】:postgres error: column doesn't exist error in Postgesql 11.6postgres 错误:Postgresql 11.6 中的列不存在错误
【发布时间】:2020-11-12 19:36:14
【问题描述】:

我正在尝试通过以下语法在 postgresql 11.6 上运行更新命令

 update "YP_SUPPLIERS" set "YP_SUPPLIERS.supplierName" = "update" where "YP_SUPPLIERS.supplierID" = da68e9d0-1100-43e2-0011-db8fbe654321;

我收到以下错误

ERROR:  column "YP_SUPPLIERS.supplierID" does not exist

第 1 行:...设置 "YP_SUPPLIERS.supplierName" = "update" where "YP_SUPPLI...

只给出列名,删除引号,但似乎没有任何效果。

谁能给我一个正确的方法。

【问题讨论】:

标签: postgresql postgresql-11 quoted-identifier string-constant


【解决方案1】:

您需要单独引用每个元素,并且针对目标列不需要重复表格。在 SQL 中,字符串常量需要用单引号 (') 括起来。双引号用于标识符。

 update "YP_SUPPLIERS" 
     set "supplierName" = 'update' --<< single quotes for constant values
 --     ^ no table name here
 where "YP_SUPPLIERS"."supplierID" = 'da68e9d0-1100-43e2-0011-db8fbe654321';
 --    ^ schema and table name must be quoted separately

【讨论】:

  • 成功了。为什么这么复杂有没有其他方法可以做到这一点?
  • 一点也不复杂。当您使用带引号的标识符创建表时,它变得复杂了。如果你从不在 SQL 中使用双引号,从长远来看,你会少很多麻烦。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
  • 2019-07-28
  • 1970-01-01
  • 2020-12-04
相关资源
最近更新 更多