Generators - Mailing list pgsql-ports

From Fernando Braga
Subject Generators
Date
Msg-id 000b01bf05b5$8cb47780$0258c7c8@vcnet.com.br
Whole thread Raw
List pgsql-ports
Sirs,
 
I'm migrating an Interbase database to Postgres, and I'm stuck on a generator problem. There is an auto-sequencing field, which is automatically increased every time a new record is inserted. In Interbase, I issued a CREATE GENERATOR command, and a CREATE TRIGGER, just like this:
 
CREATE GENERATOR <table> <generatorname>;
 
SET TERM ^;
CREATE TRIGGER <triggername> FOR <table>
ACTIVE BEFORE INSERT POSITION 0 AS BEGIN
   NEW.<fieldname> = GEN_ID( <generatorname>, 1 );
END
^
COMMIT WORK ^
SET TERM ;^
 
I have studied Postgres a while and I haven't found a way to do so. Could you please point me a way to accomplish that ? Is it necessary for me to every time query the database for the largest number and insert this incremented number? And for heavy-loaded databases ?
 
Sincerely,
Fernando Braga
 
Attachment

pgsql-ports by date:

Previous
From: Jordi Xavier Prat Grau
Date:
Subject: postgresql port success ...
Next
From: Thomas Lockhart
Date:
Subject: Re: [PORTS] NEWBIE needs help