Re: Need magic for inserting in 2 tables

Поиск
Список
Период
Сортировка
От Andreas
Тема Re: Need magic for inserting in 2 tables
Дата
Msg-id 4CA93C9B.7010201@gmx.net
обсуждение исходный текст
Ответ на Re: Need magic for inserting in 2 tables  (Scott Marlowe <scott.marlowe@gmail.com>)
Ответы Re: Need magic for inserting in 2 tables  (Scott Marlowe <scott.marlowe@gmail.com>)
Список pgsql-sql
Am 04.10.2010 02:58, schrieb Scott Marlowe:
>
> The same way it would use the output of a select, it's a record set.
> So it's x rows by y columns.

Then where were my insert statements wrong?
Please, look this is a simple but complete example and show me my error.

create temporary table table_1 ( id_1 serial primary key, txt  text );
create temporary table table_2 as select 42::integer as id_2;
ALTER TABLE table_2 ADD CONSTRAINT t2_pkey PRIMARY KEY( id_2 );
create temporary table t1_t2 ( fk_1 integer references table_1 ( id_1 ), 
fk_2 integer references table_2 ( id_2 ) );

--  delete from table_1;

insert into t1_t2 ( fk_1, fk_2 )    insert into table_1 ( txt )    values ( 'A' ), ( 'B' ), ( 'C' )    returning id_1,
42;

The inner insert works and dumps the inserted ids along with the 
constant which is needed in the outer insert as reference to the project.

Both inserts run together give an error.


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

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: Need magic for inserting in 2 tables
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: Need magic for inserting in 2 tables