- 创建function
CREATE OR REPLACE FUNCTION user() RETURNS trigger AS $BODY$
BEGIN
NEW.ID := nextval('user$seq');
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql';
- 创建trigger
CREATE TRIGGER user
BEFORE INSERT ON user
FOR EACH ROW
WHEN (NEW.id IS NULL)
EXECUTE PROCEDURE user();
- seq
CREATE SEQUENCE user$seq OWNED BY user.id;
postgresql 实现自增ID 创建seq和触发器
最新推荐文章于 2024-10-01 07:41:35 发布