Re: Return row after a Insert - Mailing list pgsql-novice

From A. Kretschmer
Subject Re: Return row after a Insert
Date
Msg-id 20100329074414.GC21944@a-kretschmer.de
Whole thread Raw
In response to Return row after a Insert  (Carel Combrink <s25291930@tuks.co.za>)
List 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

pgsql-novice by date:

Previous
From: Carel Combrink
Date:
Subject: Return row after a Insert
Next
From: Joshua Tolley
Date:
Subject: Re: Clustering/fail-over solution