Re: auto_increment

From: "Muhyiddin A(dot)M Hayat" <middink(at)indo(dot)net(dot)id>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: auto_increment
Date: 2003-09-20 10:14:38
Message-ID: 007901c37f60$058de880$1f00a8c0@middinkcomp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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" <dev(at)archonet(dot)com>
To: "Muhyiddin A.M Hayat" <middink(at)indo(dot)net(dot)id>; <pgsql-sql(at)postgresql(dot)org>
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
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Martin Marques 2003-09-20 11:15:13 Re: auto_increment
Previous Message Richard Huxton 2003-09-20 10:05:30 Re: auto_increment