Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: how to insert null value to uuid

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)
like image 605
user4265223 Avatar asked Feb 11 '23 13:02

user4265223


1 Answers

In Postgres use uuid_nil() function to simulate empty uuid (same as 00000000-0000-0000-0000-000000000000)

INSERT INTO inv_location (address_id)
VALUES (uuid_nil())

You might need to have uuid extension (not sure), if you do, run this (only once):

create extension if not exists "uuid-ossp";
like image 70
Micha Kaufman Avatar answered Feb 19 '23 08:02

Micha Kaufman