[英]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.这可能是true
或false
,并且不能存储在定义为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.