简体   繁体   English

使用 CASE 表达式更新列抛出错误:列“external_uuid”的类型为 uuid,但表达式的类型为 boolean

[英]Updating a column by using CASE expression throwing ERROR: column "external_uuid" is of type uuid but expression is of type boolean

I have a table where I would like to do update a column external_uuid only if that column already doesn't have a value:我有一个表,我想在其中更新列external_uuid ,前提是该列已经没有值:

private const val updateSql = """
  update customer
  set
      external_id = :externalId,
      external_uuid = CASE when external_uuid is null then external_uuid = :externalUuid END,
      name = :name,
      address = :address,
      zip_code = :zipCode,
      zip_area = :zipArea,
      country_code = :countryCode,
      is_deleted = :markedForRemoval
  where is_deleted = false AND (external_uuid = :externalUuid OR (external_id = :externalId AND external_subcustomer = :subCustomer))
"""

But, if I do an update like that I get an error:但是,如果我进行这样的更新,我会收到错误消息:

 ERROR: column "external_uuid" is of type uuid but expression is of type boolean

How can I conditionally set only one column on an update?如何有条件地在更新中仅设置一列?

Your CASE expression returns the result of this boolean expression:您的CASE表达式返回此 boolean 表达式的结果:

external_uuid = :externalUuid

which may be true or false and can't be stored in a column defined as uuid and this is why you get the error.这可能是truefalse ,并且不能存储在定义为uuid的列中,这就是您收到错误的原因。

You should write it like this:你应该这样写:

external_uuid = CASE when external_uuid is null then :externalUuid else external_uuid END

or:或者:

external_uuid = coalesce(external_uuid, :externalUuid)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 varchar[ ] 列类型转换为 uuid[ ] - convert varchar[ ] column type to uuid[ ] PGError:错误:“ is_required”列为布尔类型,但表达式为整数类型 - PGError: ERROR: column “is_required” is of type boolean but expression is of type integer Rails和PSQL:如何使用回退值将STRING类型的列转换为UUID - Rails & PSQL: how to convert a column of type STRING to UUID with a fallback value 带Sequelize Cast的uuid v4类型列上的ILIKE运算符 - ILIKE Operator on uuid v4 type column with Sequelize Cast Postgresql 将列类型从 UUID 更改为 int4 - Postgresql change column type from UUID to int4 使用大小写表达式更新表列日期? - Updating table column date with case expression? java sql error列的类型为整数,但表达式的类型为字符变化 - java sql error column is of type integer but expression is of type character varying PostgreSQL错误:列“ qty”是整数类型,而表达式是文本类型 - PostgreSQL error: column “qty” is of type integer but expression is of type text SQL错误“列“ zona”的类型为box,但表达式的类型为record” - SQL error 'column “zona” is of type box but expression is of type record' 列“文件”的类型为 oid 但表达式的类型为字节 - Column "file" is of type oid but expression is of type byte
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM