开发者

How to convert "" to NULL in PostgreSQL

I'm with a problem in PostgreSQL. I need to do something like this:

select * from single_occurrences
where 
age::int4 > 29

And I got this error:

ERROR:  invalid input syntax for integer: ""

The field age is a text field. How can I convert all the "" va开发者_Python百科lues to NULL values?

Best Regards,


SELECT *
  FROM single_occurrences
 WHERE CASE WHEN age="" THEN NULL ELSE age::int4 END > 29


UPDATE single_occurrences SET age=NULL WHERE age="";

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜