Search Postgresql Archives

Re: Serial - last value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux