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: 20080828222246.GH8424@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

In response to

Responses

Browse pgsql-general by date

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