From: | Thom Brown <thom(at)linux(dot)com> |
---|---|
To: | Nick Apperson <apperson(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Chaining inserts ... This would be cool |
Date: | 2012-04-23 21:19:10 |
Message-ID: | CAA-aLv6MYLDL_bi8=-EEmR9GGmASdCOwdTSjZNSdeVnMrbqjFg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 23 April 2012 21:49, Nick Apperson <apperson(at)gmail(dot)com> wrote:
> There are obviously workarounds for this, but I'm wondering why the
> following query shouldn't work. It seems like it should. With MVCC already
> present on the back-end, I can't see any reason other than additional
> parsing routines that this couldn't work:
>
> INSERT INTO old_login_id_to_new_account_id(new_account_id, old_login_id)
> INSERT INTO accounts(id, username, password_hash, email) SELECT DEFAULT,
> username, password_hash, email FROM logins_old RETURNING id, logins_old.id;
>
> Anyway, I'm sure there are more important features for Postgres (like
> upserts, unique indexes on GIN, Gist and hash, fixed arrays, compact storage
> of enum arrays as bitfields, etc.) I just thought it was an interesting
> idea.
You should be able to use writeable common table expressions to
achieve a linking behaviour.
http://www.postgresql.org/docs/9.1/static/queries-with.html
http://www.depesz.com/index.php/2011/03/16/waiting-for-9-1-writable-cte/
http://thombrown.blogspot.de/2011/11/writeable-common-table-expressions.html
But I'm not sure the query you posted makes any sense. Why would a
SELECT statement have a RETURNING clause? And where do the values for
the first INSERT come from?
--
Thom
From | Date | Subject | |
---|---|---|---|
Next Message | Nick Apperson | 2012-04-23 21:34:06 | Re: Chaining inserts ... This would be cool |
Previous Message | Nick Apperson | 2012-04-23 20:49:18 | Chaining inserts ... This would be cool |