Re: Serial - last value - Mailing list pgsql-general

From Richard Huxton
Subject Re: Serial - last value
Date
Msg-id 492669C3.5000307@archonet.com
Whole thread Raw
In response to Serial - last value  ("hendra kusuma" <penguinroad@gmail.com>)
List 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

pgsql-general by date:

Previous
From: WireSpot
Date:
Subject: Re: Prepared statement already exists
Next
From: "Sergey Moroz"
Date:
Subject: transaction isolation level in plpgsql function