在数据表中使用uuid默认值

最近更新时间: 2024-10-17 17:10:00

postgres=# create table t_uuid(f1 uuid not null default uuid_generate_v1(),f2 varchar(256) );
CREATE TABLE
postgres=# \d+ t_uuid 
                                             Table "public.t_uuid"
 Column |          Type          |              Modifiers              | Storage  | Stats target | Description 
--------+------------------------+-------------------------------------+----------+--------------+-------------
 f1     | uuid                   | not null default uuid_generate_v1() | plain    |              | 
 f2     | character varying(256) |                                     | extended |              | 
Has OIDs: no
Distribute By SHARD(f2)
        Location Nodes: ALL DATANODES
postgres=# insert into t_uuid (f2) values(uuid_generate_v4());
INSERT 0 1
postgres=# select * from t_uuid;
                  f1                  |                  f2                  
--------------------------------------+--------------------------------------
 75dfb6b0-c382-11e7-9f82-525400efe0ca | 2b99799c-d77e-4023-81db-3e5c6ad901b0
(1 row)