Insert Null value in inet field in postgresql

I am trying to insert values ​​into a table that contains two columns with inet types. When I try to insert a NULL value in these columns, I get an error

ERROR: invalid input syntax for type inet: ""

Actually, I am trying to do this from python using sqlalchemy, but naturally I get the same error:

Error Session.commit (): (DataError) Invalid input syntax for type inet: ""

I need to be able to add null values ​​to these columns. These columns do not have an attribute of type NOT NULL .

+6
source share
1 answer

The error message seems to indicate that you are using an empty string to indicate a null value, which is incorrect.

The following should work:

 INSERT INTO my_table (inet_column) VALUES (NULL); 

Or, if you actually mean updating instead of pasting:

 UPDATE my_table SET inet_column = NULL WHERE pk_column = 42; 
+10
source

Source: https://habr.com/ru/post/886039/


All Articles