Reputation: 105
I need help in converting the below query to 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;
Upvotes: 0
Views: 249
Reputation: 31726
In case you want to use a desired sequence in Postgres, you may do.
create sequence REQUESTOR_SEQ;
create table REQUESTOR ( id int DEFAULT NEXTVAL('requestor_seq') )
Otherwise a serial
column would suffice.
Upvotes: 2
Reputation: 1271151
In Postgres, you don't use sequences for this purpose. Just use a serial
column and dispense with the trigger:
create table requestor (
id serial primary key,
. . .
);
Upvotes: 1