[SQL] join returns too many results...

2010-10-03 Thread Frank Bax
When I join tables; I will sometimes get multiple rows back as in this example. create table class(name varchar, p point, d int); insert into class values( 'All', point(50,50), 100 ); insert into class values( 'NE70', point(70,70), 20 ); insert into class values( 'NE75', point(75,75), 20 );

[SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Andreas
Hi, I need to insert a lot of basically blank records into a table to be filled later. Sounds silly but please bear with me. :) projects ( project_id, project_name, ... ) companies ( company_id, ... ) departments ( department_id, department ) staff ( staff_id SERIAL, company_fk,

Re: [SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Scott Marlowe
On Sun, Oct 3, 2010 at 4:14 PM, Andreas maps...@gmx.net wrote: insert into staff ( company_fk, ..., department_fk ) select  company_fk, ..., department_fk from     departments,   companies,   company_2_project  AS c2p where  company_id      =   c2p.company_fk    and c2p.project_fk    =   42  

Re: [SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Andreas
Am 04.10.2010 01:46, schrieb Scott Marlowe: On Sun, Oct 3, 2010 at 4:14 PM, Andreasmaps...@gmx.net wrote: insert into staff ( company_fk, ..., department_fk ) select company_fk, ..., department_fk from departments, companies, company_2_project AS c2p where company_id =

Re: [SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Scott Marlowe
On Sun, Oct 3, 2010 at 6:47 PM, Andreas maps...@gmx.net wrote: How can a script use what RETURNING dumps out? I tried a bit but got nowhere. The same way it would use the output of a select, it's a record set. So it's x rows by y columns. -- To understand recursion, one must first understand

Re: [SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Andreas
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 (

Re: [SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Scott Marlowe
On Sun, Oct 3, 2010 at 8:31 PM, Andreas maps...@gmx.net wrote: 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