Re: Serial - last value

From: Richard Huxton <dev(at)archonet(dot)com>
To: hendra kusuma <penguinroad(at)gmail(dot)com>, PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Serial - last value
Date: 2008-11-21 07:56:51
Message-ID: 492669C3.5000307@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hendra kusuma wrote:
>
> Let me get this clear
> it should looks like this?
>
> create function something() returns integer as $$
> declare
> ret integer;
> begin
> -- just assume something table has a serial column as primary key
> insert into something values ('a value');
> select currval('something_sequence') into ret;
> return ret;
> end
>
> $$ language 'plpgsql';

That should work fine, although for that particular case with recent
versions you could just use:

INSERT INTO some_table (id, mytext) VALUES (DEFAULT, 'a value')
RETURNING id;

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2008-11-21 08:46:34 Re: where in (select array)
Previous Message WireSpot 2008-11-21 07:55:11 Re: Prepared statement already exists