我有这个查询,当 t.delete_req='1' 和 t.delete_req='0' 时,我需要设置 'yes' 和 'no'
SELECT t.id,t.activity_id,t.type,t.sub_type,t.name,t.description,t.source,
CASE t.delete_req WHEN t.delete_req='1' THEN 'Yes' WHEN t.delete_req='0' THEN 'No' END from "activities" "t"
它抛出错误并说存在一些铸造问题。下面是错误。
ERROR: operator does not exist: character = boolean
LINE 2: CASE t.delete_req WHEN t.delete_req='1' THEN 'Yes' WHEN t.de...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
现在我尝试以这种方式进行转换,// CAST(t.delete_req AS char)='1'
SELECT t.id,t.activity_id,t.type,t.sub_type,t.name,t.description,t.source,
CASE t.delete_req
WHEN CAST(t.delete_req AS char)='1' THEN 'Yes'
WHEN CAST(t.delete_req AS char)='0' THEN 'No' END from "activities" "t"
但我仍然无法让它工作。错误是一样的。
ERROR: operator does not exist: character = boolean
在表中,t.delete_req 是一个字符,定义如下。
delete_req character(1) NOT NULL DEFAULT '0'::bpchar,