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

Re: getting auto increment id value

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: M(dot) Emre Çolak <memrecolak(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: getting auto increment id value
Date: 2011-12-20 14:38:27
Message-ID: CAK3UJREU8nK7zhWrHBgbsxWA54ztXo_c5XWbkewL3XLfvCGL1Q@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Tue, Dec 13, 2011 at 3:52 AM, M. Emre Çolak <memrecolak(at)hotmail(dot)com> wrote:

>   I have a table and it's only distinct value is it's auto incremented id. I
> need to insert like 80.000 rows at ones so I have some time issues. Problem
> is I need a way to get a return value which is id of my inserted row since I
> need that id for another insert action. I think I should use a function for
> this but I am not sure how I can get Id of my inserted row.

Use INSERT INTO tbl ... RETURNING your_auto_inc_column. See also the
docs for the RETURNING clause at:
  http://www.postgresql.org/docs/current/static/sql-insert.html

Josh

In response to

pgsql-novice by date

Next:From: Daniel NorthamDate: 2011-12-21 18:50:04
Subject: TRIGGER FUNCTION - TO CREATE TABLE name AS SELECT
Previous:From: Jean-Yves F. BarbierDate: 2011-12-19 16:37:02
Subject: Re: How to establish a SSL connection to a postgresql server

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