PostgreSQL: how to insert null value to uuid
·
Answer a question
Need to insert null value to field with uuid type without NOT NULL specification (not primary key).
When I try insert '', this return:
ERROR: invalid input syntax for uuid: ""
When I try insert null, this return:
ERROR: null value in column "uuid" violates not-null constraint
How to do it?
psql 9.3.5
SQL:
INSERT INTO inv_location (address_id)
VALUES (null)
Answers
If the column is defined NOT NULL, you cannot enter a NULL value. Simple as that.
uuid in the error message:
ERROR: null value in column "uuid" violates not-null constraint
is the name of the column:
uuid | character varying(36) | not null
Not the data type of address_id. And this column is obviously defined NOT NULL.
Your INSERT statement does not include uuid in the target list, so NULL is assigned to it in the absence of a different column default. Bang.
Goes to show that it's a bad idea to use type names as identifiers: leads to confusing error messages (and other confusion).
更多推荐
所有评论(0)