Re: helo

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: helo
Date: 2010-01-21 06:04:22
Message-ID: 20100121060421.GA10401@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

  • helo at 2010-01-21 04:01:26 from beulah prasanthi

Browse pgsql-general by date

  From Date Subject
Next Message Gerd Koenig 2010-01-21 07:02:50 Re: function to grant select on all tables in several schemas
Previous Message John R Pierce 2010-01-21 04:13:00 Re: helo