Skip site navigation (1) Skip section navigation (2)

Re: MySQL LAST_INSERT_ID() to Postgres

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Russ Brown <pickscrape(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: MySQL LAST_INSERT_ID() to Postgres
Date: 2008-08-28 22:22:46
Message-ID: (view raw or whole thread)
Lists: pgsql-general
Russ Brown escribió:
> Masis, Alexander (US SSA) wrote:
> > 
> > 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();

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

Alvaro Herrera                      
The PostgreSQL Company - Command Prompt, Inc.

In response to


pgsql-general by date

Next:From: D. Dante LorensoDate: 2008-08-28 22:23:36
Subject: Re: MySQL LAST_INSERT_ID() to Postgres
Previous:From: Matthew DennisDate: 2008-08-28 22:21:59
Subject: Re: indexes on functions and create or replace function

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group