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

Re: MySQL LAST_INSERT_ID() to Postgres

From: Russ Brown <pickscrape(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: MySQL LAST_INSERT_ID() to Postgres
Date: 2008-08-28 19:51:21
Message-ID: 48B701B9.8010303@gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
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;

In response to

Responses

pgsql-general by date

Next:From: Steve AtkinsDate: 2008-08-28 19:56:44
Subject: Re: MySQL LAST_INSERT_ID() to Postgres
Previous:From: Alan HodgsonDate: 2008-08-28 19:49:24
Subject: Re: WAL file questions - how to relocate on Windows, how to replay after total loss, etc

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