postgresql 列是布尔类型,但表达式是文本类型 提示:您需要重写或强制转换表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37756841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:18:31  来源:igfitidea点击:

Column is of type Boolean but expression is of type text Hint: You will need to rewrite or cast the expression

postgresqlpostgresql-9.3postgresql-9.4

提问by Ramesh

Can anyone help me with the error?

谁能帮我解决这个错误?

Update table 
SET
tentative = case src.tentative 
WHEN 1 THEN 't' ELSE 'f' END
FROM table 

回答by Nick

Your column tentativeis a BOOLEANtype; however, you are trying to update it with a TEXTtype value.

你的专栏tentative是一种BOOLEAN类型;但是,您正在尝试使用TEXT类型值更新它。

All you need to do is use BOOLEANin your update like so:

您需要做的就是BOOLEAN在更新中使用,如下所示:

UPDATE table 
SET tentative = CASE src.tentative WHEN 1 THEN TRUE ELSE FALSE END
FROM src_table src;

Alternatively, but maybe less obvious you can do this:

或者,但可能不太明显,您可以这样做:

UPDATE table 
SET tentative = (src.tentative = 1)
FROM src_table src;