您的位置:首页 > 博客中心 > 数据库 >

Postgresql UUID的使用。

时间:2022-03-14 00:00

PostgreSQL内置uuid类型,性能不错,但是PostgreSQL默认没有安装uuid相关操作函数,需要手动导入。

导入uuid相关函数。

psql -d dbname -U dbuser -f D:/develop/database/PostgreSQL/9.3/share/contrib/uuid-ossp.sql

定义uuid作为主键,并自动生成主键

REATE TABLE data_2014.test
(
  uid uuid NOT NULL DEFAULT uuid_generate_v1(),
  name character varying(32),
  CONSTRAINT test_pkey PRIMARY KEY (uid)
)
WITH (
  OIDS=FALSE
);

java中内置了uuid函数,这个函数在数据量大时,曾出现过重复键,导致系统出问题。

java.util.UUID.randomUUID().toString();

除此之外,可以使用com.eaio.uuid.UUID

new com.eaio.uuid.UUID().toString();


热门排行

今日推荐

热门手游