Re: DB2-style INS/UPD/DEL RETURNING

From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Dave Cramer" <pg(at)fastcrypt(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: DB2-style INS/UPD/DEL RETURNING
Date: 2006-03-13 15:52:39
Message-ID: 36e682920603130752w4dc4d954leafc11426effe6b8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 3/13/06, Dave Cramer <pg(at)fastcrypt(dot)com> wrote:
>
> One of the purposes of this as I understand it is to allow clients to
> get back the generated key(s). I don't see enough of the syntax to
> see if this is possible with the DB2 syntax below.

I believe it would be something like

CREATE SEQUENCE test_id_seq;
CREATE TABLE test_tbl (test_id bigint not null default
nextval('test_id_seq'), test_name varchar(32), PRIMARY KEY(test_id));

To get the generated sequence:
SELECT test_id FROM NEW TABLE INSERT INTO test_tbl VALUES
(nextval('test_id_seq'), 'Joe Blow');
The reason for NEW is because there is no OLD version of the record.

In contrast, something similar to:
SELECT test_name FROM OLD TABLE UPDATE test_tbl SET test_name = 'John Doe'
WHERE test_id = 1;
would return "Joe Blow"

Whereas:
SELECT test_name FROM NEW TABLE UPDATE test_tbl SET test_name = 'John Doe'
WHERE test_id = 1;
would return "John Doe"

Again, I haven't really used it, but have read over the docs briefly. I'm
just wondering if anyone has used it and likes/dislikes it.

--
Jonah H. Harris, Database Internals Architect
EnterpriseDB Corporation
732.331.1324

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-03-13 16:04:16 Re: Transaction eating up all RAM
Previous Message Jan de Visser 2006-03-13 15:32:03 Re: [PERFORM] Hanging queries on dual CPU windows