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
Column is of type Boolean but expression is of type text Hint: You will need to rewrite or cast the expression
提问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 tentative
is a BOOLEAN
type; however, you are trying to update it with a TEXT
type value.
你的专栏tentative
是一种BOOLEAN
类型;但是,您正在尝试使用TEXT
类型值更新它。
All you need to do is use BOOLEAN
in 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;