X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id CF048D1B57B for ; Sat, 20 Sep 2003 11:01:01 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 22670-01 for ; Sat, 20 Sep 2003 08:00:53 -0300 (ADT) Received: from smtp-1.indo.net.id (smtp-1.indo.net.id [202.159.32.91]) by svr1.postgresql.org (Postfix) with SMTP id 5091DD1B57E for ; Sat, 20 Sep 2003 08:00:48 -0300 (ADT) Received: (qmail 4798 invoked from network); 20 Sep 2003 18:00:47 +0700 Received: from smtp.indo.net.id (202.159.32.81) by smtp-1.indo.net.id with SMTP; 20 Sep 2003 18:00:47 +0700 Received: (qmail 1257 invoked from network); 20 Sep 2003 10:58:39 -0000 Received: from unknown (HELO smtp) (202.159.51.117) by smtp.indo.net.id with SMTP; 20 Sep 2003 10:58:39 -0000 Received: FROM middinkcomp BY smtp ; Sat Sep 20 18:10:36 2003 +0700 Message-ID: <007901c37f60$058de880$1f00a8c0@middinkcomp> From: "Muhyiddin A.M Hayat" To: References: <001d01c37f3e$983ed3a0$2363a8c0@ckeskin> <002201c37f54$29608e40$1f00a8c0@middinkcomp> <200309201105.30370.dev@archonet.com> Subject: Re: auto_increment Date: Sat, 20 Sep 2003 18:14:38 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/219 X-Sequence-Number: 15197 Where/How can i put this below sql statement, to set value of guest_guest_id_seq before i do insert to table SELECT setval('guest_guest_id_seq', max(guest.guest_id)) FROM guest; i have been try CREATE TRIGGER "before_insert_guest_update_room_number" BEFORE INSERT ON "public"."guest" FOR EACH ROW EXECUTE PROCEDURE "public"."generate_guest_id"(); but error ----- Original Message ----- From: "Richard Huxton" To: "Muhyiddin A.M Hayat" ; Sent: Saturday, September 20, 2003 6:05 PM Subject: Re: [SQL] auto_increment > On Saturday 20 September 2003 09:43, Muhyiddin A.M Hayat wrote: > > Ok, but if i do rollback, the auto_increment don't roolback. > > It's not supposed to. > > > How to use nextval(), currval() and setval() functions. > > Something like: > INSERT INTO my_table(nextval('my_sequence_name'),'aaa',1); > But you'll get the same problem. > > What are you trying to do with the auto-increment? If you want to guarantee > that the numbers go up in sequence and have no gaps (e.g. 1,2,3,4,5 NOT > 1,2,4,6) then you'll need to do some more work. > > Think about what you want to have happen when three clients insert rows at the > same time and one rolls back. Once you've decided what you want, ask again if > you need some help. > > -- > Richard Huxton > Archonet Ltd > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster >