安装依赖包
sudo apt install postgresql-contrib
为表添加扩展
create extension "uuid-ossp";
验证
testdb=> select uuid_generate_v4();
uuid_generate_v4
--------------------------------------
832191a7-414c-4b30-9c96-bc1b0782c784
(1 row)
创建一个使用uuid作为主键的表:
create table table_name
(
id UUID PRIMARY KEY DEFAULT uuid_generate_v4()
);