Re: new rows based on existing rows

Поиск
Список
Период
Сортировка
От Chris Angelico
Тема Re: new rows based on existing rows
Дата
Msg-id CAPTjJmoSr=vGeQ41pfPQpJ-ye6vfQnmq9XNpLy778+2eHPykTg@mail.gmail.com
обсуждение исходный текст
Ответ на new rows based on existing rows  (Andy Chambers <achambers@mcna.net>)
Список pgsql-general
On Wed, May 2, 2012 at 10:52 PM, Andy Chambers <achambers@mcna.net> wrote:
> 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?

I'd recommend not using OIDs but having your own ID field (eg a
[BIG]SERIAL PRIMARY KEY). Is the mapping of old ID to new ID something
that would be worth saving into the table? Even if you don't need it
later, that might be the easiest way to do the job. Alternatively, you
could play around with joins (an INSERT RETURNING can quite happily be
used in a WITH clause) to see if you can get what you want that way.

ChrisA

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

Предыдущее
От: Radosław Smogura
Дата:
Сообщение: Re: Which Java persistence library would you use with PostgreSQL?
Следующее
От: leaf_yxj
Дата:
Сообщение: Re: How to insert random character data into tables for testing purpose. THanks.