Can an integer column be null?

efoc picture efoc · Sep 28, 2017 · Viewed 22.7k times · Source

I made an integer column that is null by default but when I put empty double quotes "" it gives this error:

ERROR: invalid input syntax for integer: ""

Does the integer column have to be 0 then?

I am using Java to send the query to the database.

Answer

Sam Hartman picture Sam Hartman · Sep 28, 2017

An integer column can be null, but '' is an empty string not null. The right syntax for a null integer (or any other sql type) is null.