I am trying to insert values to a table which contains two columns with inet types. When I try to insert a NULL value to these columns I get an error saying
ERROR: invalid input syntax for type inet: ""
Actually I am triyng to do this from python using sqlalchemy but naturally I get the same error saying:
Session.commit() error: (DataError) invalid input syntax for type inet: ""
I need to be able to add null values to these columns.
These colums do not have an attribute like NOT NULL.
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 .
With the current psycopg, instead of None, use a variable set to 'NULL'. If the field being inserted is a text field, using 'NULL', simply inserts those four characters. The answer above (use None ) is the correct one.
nullif also used with the coalesce function to handle the null values. PostgreSQL nullif function returns a null value if provided expressions are equal. If two expressions provided are equal, then it provides a null value; as a result, otherwise, it will return the first expression as a result.
Answer: No, Each null value only uses one bit on disk.
The error message seems to indicate you are using an empty string to indicate a "null" value which is not correct.
The following should work:
INSERT INTO my_table (inet_column) VALUES (NULL);
Or if you actually mean update instead of insert:
UPDATE my_table
SET inet_column = NULL
WHERE pk_column = 42;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With