Re: INSERT ... RETURNING in v8.2

From: Tom Allison <tom(at)tacocat(dot)net>
To: Vincenzo Romano <vincenzo(dot)romano(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT ... RETURNING in v8.2
Date: 2007-06-16 12:02:41
Message-ID: 8E77CF32-BFEF-4254-999B-5104A574D0E7@tacocat.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Jun 12, 2007, at 10:18 AM, Vincenzo Romano wrote:

>
> Hi all.
> I'm trying to use this wonderful feature (thanks to anyone who
> suggested/committed/implemented it).
>
> According to the documentation:
> (http://www.postgresql.org/docs/8.2/interactive/sql-insert.html)
>
> "The optional RETURNING clause causes INSERT to compute and return
> value(s) based on each row actually inserted. This is primarily
> useful for obtaining values that were supplied by defaults, such
> as a serial sequence number. However, any expression using the
> table's columns is allowed. The syntax of the RETURNING list is
> identical to that of the output list of SELECT."

Holy Crud!
you mean to tell me I can replace:

insert into table(string) values(('one'),('two'),('three'));
select idx from table where string in ('one','two','three');

with

insert into table(string) values(('one'),('two'),('three')) returning
idx;

?????

I realize that this is an extension to standard SQL but it sure would
save me a lot.

I'm wondering just how many other things I'm missing....
(I am really starting to like this database more every week)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Allison 2007-06-16 12:04:10 Re: INSERT ... RETURNING in v8.2
Previous Message Tom Allison 2007-06-16 11:36:08 Re: Using the GPU