Re: Multiple inserts into 2 tables with FKs

Поиск
Список
Период
Сортировка
От Tiemo Kieft
Тема Re: Multiple inserts into 2 tables with FKs
Дата
Msg-id 468AB628.9060004@gmail.com
обсуждение исходный текст
Ответ на Re: Multiple inserts into 2 tables with FKs  ("Josh Tolley" <eggyknap@gmail.com>)
Список pgsql-novice
Josh Tolley wrote:
> If I understand the problem correctly, you might do something like
> this (if you're using 8.2 and have INSERT...RETURNING):
>
> INSERT INTO filename (filename_name) VALUES ('some_filename_here')
> RETURNING filename_id;
>
> This will return a value, for instance, 10. Then you'd do this:
>
> INSERT INTO path (path_filename_id, path) VALUES (10, 'your_path_here');
But what if the filename is already in the filenames table? It will give
an error due to duplicate values, so I'll have to do a SELECT after
that? I was kind of hoping there was a somewhat more elegant solution to
this.

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

Предыдущее
От: "Josh Tolley"
Дата:
Сообщение: Re: Multiple inserts into 2 tables with FKs
Следующее
От: "David Monarchi"
Дата:
Сообщение: COPY and index updating