Re: Return row after a Insert

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Return row after a Insert
Date: 2010-03-29 07:44:14
Message-ID: 20100329074414.GC21944@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

In response to Carel Combrink :
> I have a Table that looks something like this:
>
> CREATE TABLE My_Table(
> Entry integer PRIMARY KEY DEFAULT nextval('Number'),
> TimeInsert timestamp DEFAULT current_timestamp,
> Severity ENUM_Severity NOT NULL,
> String varchar(512)
> );
>
> where Number is a SEQUENCE and ENUM_Severity is an ENUM
>
> There are 2 things I want to do.
>
> After an INSERT statement I want to be able to know what was the
> 'Entry' number I just added. I was thinking on creating an AFTER

You can use RETURNING *
http://www.postgresql.org/docs/current/static/sql-insert.html

Or just for the SERIAL currval().

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Joshua Tolley 2010-03-29 18:59:16 Re: Clustering/fail-over solution
Previous Message Carel Combrink 2010-03-29 07:21:19 Return row after a Insert