Re: helo - Mailing list pgsql-general

From A. Kretschmer
Subject Re: helo
Date
Msg-id 20100121060421.GA10401@a-kretschmer.de
Whole thread Raw
In response to helo  (beulah prasanthi <itsbeulah@gmail.com>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Adrian von Bidder
Date:
Subject: Re: more docs on extending postgres in C
Next
From: Gerd Koenig
Date:
Subject: Re: function to grant select on all tables in several schemas