Received: from lucas.mandanet.ch (lucas.mandanet.ch [195.15.14.192]) by hub.org (8.8.8/8.7.5) with SMTP id CAA15750 for ; Tue, 19 May 1998 02:52:41 -0400 (EDT) Received: from thomas.mandanet.ch (thomas.mandanet.ch [195.15.14.193]) by lucas.mandanet.ch (NTMail 3.02.13) with ESMTP id ka007108 for ; Tue, 19 May 1998 08:56:31 +0100 Message-ID: <35612D1E.CC49CA67@mandanet.ch> Date: Tue, 19 May 1998 08:56:30 +0200 From: Jerome Knobl Organization: MandaNET X-Mailer: Mozilla 4.04 [en] (WinNT; I) MIME-Version: 1.0 To: wwwadmin@wizard.ca CC: PGsql Subject: Re: [SQL] How to handle a requirement for nextval References: <35609B0F.52A63C2@wizard.ca> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I have got the same trouble. I found a first inellegant solution. Is to create a function which make an increment like that : create function last98_20_rubriques() returns int4 as 'Select max(ref98_20_rubriques) as next from DB98_20_rubriques;' language 'sql'; But I read yesterday that I have to use e SEQUENCE like : create table toto (id int4 PRIMARY KEY, test varchar); create sequence step1 increment 1 start 1000 minvalue 1000 maxvalue 999999; And after that I have normaly to do : insert into toto (id,test) values (step1.nextval,'sdf'); But It's don't work. If you can go further send me a mail (and sorry for my very bad english). JK The Web Administrator wrote: > I am still struggling on a few issues, have got my first little database > up and running, and am quite happy with PostGres, but I cannot figure > out how to create a table which can have a field that autoincrements.. > I am sure that somewhere in the oid terminology it is built in, but I > want to have a counter on some table entries.. ie... > CREATE TABLE clothing_type ( > type_id INT NOT NULL, > description TEXT, > for_sex CHAR > ); > INSERT INTO clothing_type ( > description, > for_sex > ) VALUES ( > 'pants', > 'm' > ); > > What I want is that the Primary Key (Only Key) be type_id, and int, and > the first item that I insert should have type_id as '1', next will be > '2' etc.. > I could have every insert into this table include a type_id, but that > seems unessary. > Can I have something like default='nextval' ?