[英]Need help in converting Oracle trigger to PostgreSQL
I need help in converting the below query to postgres. 在将以下查询转换为postgres时,我需要帮助。 Any help is greatly appreciated 任何帮助是极大的赞赏
CREATE TRIGGER REQUESTOR_TRG
BEFORE INSERT ON REQUESTOR
FOR EACH ROW
BEGIN
<<COLUMN_SEQUENCES>>
BEGIN
IF INSERTING AND :NEW.ID IS NULL THEN
SELECT REQUESTOR_SEQ.NEXTVAL INTO :NEW.ID FROM SYS.DUAL;
END IF;
END COLUMN_SEQUENCES;
END;
In case you want to use a desired sequence in Postgres, you may do. 如果您想在Postgres中使用所需的序列,可以这样做。
create sequence REQUESTOR_SEQ;
create table REQUESTOR ( id int DEFAULT NEXTVAL('requestor_seq') )
Otherwise a serial
column would suffice. 否则,一个serial
列就足够了。
In Postgres, you don't use sequences for this purpose. 在Postgres中,您无需为此使用序列。 Just use a serial
column and dispense with the trigger: 只需使用serial
列并免除触发器:
create table requestor (
id serial primary key,
. . .
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.