helo

Started by beulah prasanthiabout 16 years ago3 messagesgeneral
Jump to latest
#1beulah prasanthi
itsbeulah@gmail.com

I am using postgres 8.4
using views i retrived some details from multiple tables
can i insert the data into multiple tables using views.if not
how can i insert the data into multiple tables in a single trip
is there any option .Please help me

#2John R Pierce
pierce@hogranch.com
In reply to: beulah prasanthi (#1)
Re: helo

beulah prasanthi wrote:

I am using postgres 8.4
using views i retrived some details from multiple tables
can i insert the data into multiple tables using views.if not
how can i insert the data into multiple tables in a single trip
is there any option .Please help me

use a transaction bracketed by BEGIN; and COMMIT; to execute a series
of inserts or updates as a single atomic operation.

#3A. Kretschmer
andreas.kretschmer@schollglas.com
In reply to: beulah prasanthi (#1)
Re: helo

In response to beulah prasanthi :

I am using postgres 8.4
using views i retrived some details from multiple tables
can i insert the data into multiple tables using views.if not
how can i insert the data into multiple tables in a single trip
is there any option .Please help me

You can use a RULE, simple example:

test=# create table a (a int);
CREATE TABLE
test=*# create table b (b int);
CREATE TABLE
test=*# commit;
COMMIT
test=# create view view_ab as select a.a, b.b from a left join b on a.a=b.b;
CREATE VIEW
test=*# commit;
COMMIT
test=# create rule rule_ab as on insert to view_ab do instead (insert into a values (new.a); insert into b values(new.b););
CREATE RULE
test=*# insert into view_ab values (1,1);
INSERT 0 1
test=*# select * from a;
a
---
1
(1 row)

test=*# select * from b;
b
---
1
(1 row)

test=*# select * from view_ab;
a | b
---+---
1 | 1
(1 row)

test=*#

Bernd Helme is working on 'updateable VIEWS', but i don't know the
actual status of this patch.

Upcoming new release (8.4+1) maybe contains writeable CTE, another way
to do this. (insert into multiple tables)

And yes, as said, you can use a transaction (begin; insert ...; insert
...; commit;)

Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99