Re: last id

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: ramil(at)astra(dot)ph, pgsql-novice(at)postgresql(dot)org
Subject: Re: last id
Date: 2003-06-27 04:28:56
Message-ID: 200306262128.56135.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Ramil,

> 1. insert a row to table A
> 2. get the value of the serial field from the now in no.1
> 3. insert a row to table B (one of the fields uses the value from no.2)
>
> in -one transaction-?

BEGIN TRANSACTION

INSERT INTO table_a ( 2, 3, 4 )
VALUES ( x, y, z );
INSERT INTO table_b ( a_FK, 3, 4 )
VALUES ( CURRVAL('table_a_seq'), m, q );

COMMIT TRANSACTION

Easy, neh? Now go to the online docs and do some reading about Sequences.

--
Josh Berkus
Aglio Database Solutions
San Francisco

In response to

  • last id at 2003-06-27 03:41:35 from Ramil G. Sagum

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Giorgio Ponza 2003-06-27 07:37:19 Probably a stupid question
Previous Message Ramil G. Sagum 2003-06-27 03:41:35 last id