X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1D82CD7771 for ; Fri, 2 Sep 2005 06:35:25 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26626-02 for ; Fri, 2 Sep 2005 09:35:23 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id D1CF6D7770 for ; Fri, 2 Sep 2005 06:35:20 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 685074153FC; Fri, 2 Sep 2005 10:35:16 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 503A615F1D; Fri, 2 Sep 2005 10:33:40 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 25885-04; Fri, 2 Sep 2005 10:33:37 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 547A415F1C; Fri, 2 Sep 2005 10:33:37 +0100 (BST) Message-ID: <43181C70.4040600@archonet.com> Date: Fri, 02 Sep 2005 10:33:36 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-2?Q?Graf_L=E1szl=F3?= Cc: pgsql-sql@postgresql.org Subject: Re: Returning with the inserted id References: <431816D1.4060905@axis.hu> In-Reply-To: <431816D1.4060905@axis.hu> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.057 required=5 tests=[AWL=0.007, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200509/9 X-Sequence-Number: 22556 Graf L=E1szl=F3 wrote: >=20 > A sequence to hold the id was defined with: > CREATE SEQUENCE "public"."test_azon_seq" > INCREMENT 1 MINVALUE 101 > MAXVALUE 9223372036854775807 START 101 > CACHE 1; >=20 > The function wich allocates the id and defines the datum is: > CREATE FUNCTION test_verif() RETURNS trigger AS $test_verif$ > BEGIN > select into NEW.id nextval('test_azon_seq'); > NEW.datum :=3D current_timestamp; > RETURN NEW; > END; > $test_verif$ LANGUAGE plpgsql; I take it this is just an example, because you could do this with=20 DEFAULTs on both columns. > When I issue an insert (see below) how can I retrieve the > inserted value of id? I need something like Oracle's returns > for insert. >=20 > insert into "public"."test" (nev) values ('text'); SELECT currval('public.test_azon_seq'); And yes, it will cope with multiple concurrent connections inserting. -- Richard Huxton Archonet Ltd