Search Postgresql Archives

Re: MySQL LAST_INSERT_ID() to Postgres

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

 



Russ Brown escribió:
> Masis, Alexander (US SSA) wrote:
> > 
> >    "SELECT CURRVAL(
> > pg_get_serial_sequence('my_tbl_name','id_col_name'));"
> 
> Any reason why you can't just do this?
> 
> CREATE FUNCTION last_insert_id() RETURNS bigint AS $$
>   SELECT lastval();
> $$ LANGUAGE SQL VOLATILE;

If your table has a trigger that inserts into another table with its own
sequence, you're screwed.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


[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