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).

Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐