Skip site navigation (1) Skip section navigation (2)

Re: Best possible way to insert and get returned ids

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Jason Dictos <jdictos(at)barracuda(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Best possible way to insert and get returned ids
Date: 2009-11-25 14:40:00
Message-ID: 603c8f070911250640u6cfdd734k1b9bfad6c086080@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performance
On Mon, Nov 23, 2009 at 3:53 PM, Jason Dictos <jdictos(at)barracuda(dot)com> wrote:
> Is an INSERT command with a SELECT statement in the RETURNING * parameter
> faster than say an INSERT and then a SELECT? Does the RETURNING * parameter
> simply amount to a normal SELECT command on the added rows? We need to
> basically insert a lot of rows as fast as possible, and get the ids that
> were added.  The number of rows we are inserting is dynamic and is not of
> fixed length.

With INSERT ... RETURNING, you only make one trip to the heap, so I
would expect it to be faster.  Plus, of course, it means you don't
have to worry about writing a WHERE clause that can identify the
row(s) you just added.  It sounds like the right tool for your use
case.

...Robert

In response to

pgsql-performance by date

Next:From: Kevin KempterDate: 2009-11-25 15:22:01
Subject: Re: How exactly does Analyze work?
Previous:From: Richard NeillDate: 2009-11-25 12:34:26
Subject: How exactly does Analyze work?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group