André
André

Reputation: 25564

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 "" values to NULL values?

Best Regards,

Upvotes: 2

Views: 2789

Answers (2)

manji
manji

Reputation: 47978

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

Upvotes: 3

bawkstoo
bawkstoo

Reputation: 315

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

Upvotes: 2

Related Questions