Skip site navigation (1) Skip section navigation (2)

Generators

From: "Fernando Braga" <fmbraga(at)sincro(dot)com(dot)br>
To: <pgsql-ports(at)postgresql(dot)org>
Subject: Generators
Date: 1999-09-23 11:19:46
Message-ID: 000b01bf05b5$8cb47780$0258c7c8@vcnet.com.br (view raw or flat)
Thread:
Lists: 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

pgsql-ports by date

Next:From: Thomas LockhartDate: 1999-09-23 13:40:56
Subject: Re: [PORTS] NEWBIE needs help
Previous:From: Jordi Xavier Prat GrauDate: 1999-09-23 11:03:09
Subject: postgresql port success ...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group