需要在没有NOT NULL规范(不是主键)的uuid
类型的字段中插入空值。
当我尝试插入 '' 时,返回:
ERROR: invalid input syntax for uuid: ""
当我尝试插入 null 时,返回:
ERROR: null value in column "uuid" violates not-null constraint
怎么做?
psql 9.3.5
SQL:
INSERT INTO inv_location (address_id)
VALUES (null)
最佳答案
在Postgres中使用uuid_nil()
函数来模拟空uuid(与00000000-0000-0000-0000-000000000000
相同)
INSERT INTO inv_location (address_id)
VALUES (uuid_nil())
您可能需要有 uuid 扩展名(不确定),如果需要,请运行此命令(仅一次):
create extension if not exists "uuid-ossp";
关于PostgreSQL:如何向 uuid 插入空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26992821/