[GENERAL] How to insert into 2 tables from a view?

2014-12-23 Thread Chris Hoover
Hi, I am having a problem trying to figure out. I have two tables behind a view and am trying to figure out how to create the correct insert rule so that inserting into the view is redirected to the two tables. I thought I had is solved using a stored procedure, but doing an insert into view

Re: [GENERAL] How to insert into 2 tables from a view?

2014-12-23 Thread Chris Hoover
Sorry, in my haste to get the example out, a couple of typo's where in the sql. Correct sql: BEGIN; CREATE TABLE table1 ( table1_id SERIAL PRIMARY KEY, table1_field1 TEXT ); CREATE TABLE table2 ( table1_id INTEGER NOT NULL PRIMARY KEY REFERENCES table1(table1_id) ON DELETE CASCADE,

Re: [GENERAL] How to insert into 2 tables from a view?

2014-12-23 Thread David G Johnston
Chris Hoover-2 wrote Sorry, in my haste to get the example out, a couple of typo's where in the sql. Next time, don't quote the entire original wrong query... Anyway, you probably want to create a trigger on your view and do the inserts inside the trigger function. User created CREATE RULE is

Re: [GENERAL] How to insert into 2 tables from a view?

2014-12-23 Thread David G Johnston
David G Johnston wrote Chris Hoover-2 wrote Sorry, in my haste to get the example out, a couple of typo's where in the sql. Next time, don't quote the entire original wrong query... Anyway, you probably want to create a trigger on your view and do the inserts inside the trigger

Re: [GENERAL] How to insert into 2 tables from a view?

2014-12-23 Thread rob stone
On Tue, 2014-12-23 at 15:00 -0500, Chris Hoover wrote: Sorry, in my haste to get the example out, a couple of typo's where in the sql. Correct sql: BEGIN; CREATE TABLE table1 ( table1_id SERIAL PRIMARY KEY, table1_field1 TEXT ); CREATE TABLE table2 ( table1_id

Re: [GENERAL] How to insert into 2 tables from a view?

2014-12-23 Thread David G Johnston
On Tue, Dec 23, 2014 at 6:40 PM, rob stone-2 [via PostgreSQL] ml-node+s1045698n583190...@n5.nabble.com wrote: Rather strange to have two tables sharing the same primary key value. One would have thought it was a one-to-many relationship between table1 and table2. ​while not particularly

Re: [GENERAL] How to insert into 2 tables from a view?

2014-12-23 Thread Berend Tober
Chris Hoover wrote: Correct sql: BEGIN; CREATE TABLE table1 ( table1_id SERIAL PRIMARY KEY, table1_field1 TEXT ); CREATE TABLE table2 ( table1_id INTEGER NOT NULL PRIMARY KEY REFERENCES table1(table1_id) ON DELETE CASCADE, table2_field1 TEXT ); CREATE VIEW orig_table AS