在 PostgreSQL 中使用'tf'表示形式更新布尔列



我正试图以以下查询为例动态更新一些列:

UPDATE db.user_channel AS y 
set is_favourite = x.is_favourite 
FROM (VALUES ('5378f031-7c93-4557-9ea7-8a8f047c7caa', 't')) as x(id,is_favourite) 
where x.id = y.id::text

is_favourite列的类型是boolean,尽管"t"one_answers"f"在PostgreSQL中是有效的布尔表示,但我收到了以下强制转换抱怨:

SQL Error [42804]: ERROR: column "is_favourite" is of type boolean but expression is of type text
Hint: You will need to rewrite or cast the expression.
Position: 48

为什么?非常感谢。

我想你想要:

set is_favourite = ( x.is_favourite = 't' )

Postgres解析SQL语句中的't'并将其解释为"true"与从列中读取值之间存在差异。

最新更新