2

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,

2 Answers 2

3
SELECT *
  FROM single_occurrences
 WHERE CASE WHEN age="" THEN NULL ELSE age::int4 END > 29
Sign up to request clarification or add additional context in comments.

3 Comments

Unless you need to store the age of "3 months" while your at it consider changing the data type to an integer.
Or use interval while you're at it.
Surely those should be single quotes.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.