开发者

How to convert "" to NULL in PostgreSQL

开发者 https://www.devze.com 2023-02-22 11:45 出处:网络
I\'m with a problem in PostgreSQL. I need to do something like this: select * from single_occurrences where

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

精彩评论

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