pgsql在insert时自动生成uuid

事前准备test表,DDL如下

CREATE TABLE zzz_test.test (
    id uuid NOT NULL, -- 主键id
    "name" varchar NULL -- 测试值
);

-- Column comments

COMMENT ON COLUMN zzz_test.test.id IS '主键id';
COMMENT ON COLUMN zzz_test.test."name" IS '测试值';

方法一:

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
insert into zzz_test.test values(uuid_generate_v4(),'valueV1')

方法二:

CREATE EXTENSION  IF NOT EXISTS "pgcrypto";
insert into zzz_test.test values(gen_random_uuid(),'valueV2')

查看结果:

pgsql在insert时自动生成uuid_第1张图片

 

你可能感兴趣的:(pgsql,linq,wpf,p2p)