new rows based on existing rows

Поиск
Список
Период
Сортировка
От Andy Chambers
Тема new rows based on existing rows
Дата
Msg-id CAAfW55qWE01BL-M0yYJdPe7CLawFGxTDKt7Vm2UpKs5nP1BdLw@mail.gmail.com
обсуждение исходный текст
Ответы Re: new rows based on existing rows  (Chris Angelico <rosuav@gmail.com>)
Re: new rows based on existing rows  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hi,

I frequently have a need to insert new rows into a table that are
based on existing rows but with small changes.

This is easy using something like

insert into foo (a,b,foo_date)
  select a,b,now() from foo old where ....
  returning oid

However in the application layer, I need to know which new record
corresponds with which original record

So ideally, I'd like to be able to do

insert into foo (a,b,foo_date)
  select a,b,now() from foo old where ....
  returning oid, old.oid

...but this doesn't work.  It seems you only have access to the table
being modified in a returning clause.  Is there a way I can return a
simple mapping between old oids and new oids as part of the statement
that inserts the new ones?

Cheers,
Andy

--
Andy Chambers
Software Engineer
(e) achambers@mcna.net
(t) 954-682-0573

CONFIDENTIALITY NOTICE: This electronic mail may contain information
that is privileged, confidential, and/or otherwise protected from
disclosure to anyone other than its intended recipient(s). Any
dissemination or use of this electronic mail or its contents by
persons other than the intended recipient(s) is strictly prohibited.
If you have received this communication in error, please notify the
sender immediately by reply e-mail so that we may correct our internal
records. Please then delete the original message. Thank you.

В списке pgsql-general по дате отправления:

Предыдущее
От: Evan Martin
Дата:
Сообщение: Re: SQL functions not being inlined
Следующее
От: "Albe Laurenz"
Дата:
Сообщение: Re: Significance of Postgres (version 9.1.1) Compilation parameters - Performance