ask for help !!! (emergency case)

Started by Jaruwan Laongmalalmost 25 years ago4 messages
#1Jaruwan Laongmal
jaruwan@gits.net.th

dear all
I hava 2 problems about view
1. i can't insert into view
2. i can't create view with union

I try to insert into view as following
create table t1 (id int,name varchar(12) check(id<=10));
create table t2 (id int,name varchar(12) check(id>10));
create view v1 as select * from t1,t2;
insert into v1 values(1,'wan1');
insert into v1 values(12,'wan12');

it does not show any problem but it doen't have data in table t1 and table
t2

------------------------------
if i want to distribute database into 2 database servers
and i want to insert into database1.table1 when database1.table1.id <=100
and i want to insert into database2.table2 when database2.table2.id >100

How can i do that with create view .........as .......union all ............
and insert into view ,afterthat view is check condition and distrubute data
into diferent database
up on condition

and How to configure the postgres sql server?

If you have idea or example for solving this problem , pls help me
thank you so much , i'm looking forward to seeing your response.
Regards,

#2Zeugswetter Andreas SB
ZeugswetterA@wien.spardat.at
In reply to: Jaruwan Laongmal (#1)
AW: ask for help !!! (emergency case)

I hava 2 problems about view
1. i can't insert into view

I try to insert into view as following
create table t1 (id int,name varchar(12) check(id<=10));
create table t2 (id int,name varchar(12) check(id>10));
create view v1 as select * from t1,t2;

This is not an updateable view in any database product.
It is a cartesian product join of t1 and t2.

You probably wanted:
create view v1 as
select * from t1
union all
select * from t2;

insert into v1 values(1,'wan1');
insert into v1 values(12,'wan12');

it does not show any problem but it doen't have data in table
t1 and table t2

Version 7.1 will give you an error if you don't create an appropriate
insert and update rule for the view.

Insert and update rules are not yet automatically created for views.

Andreas

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Zeugswetter Andreas SB (#2)
Re: AW: ask for help !!! (emergency case)

Zeugswetter Andreas SB <ZeugswetterA@wien.spardat.at> writes:

You probably wanted:
create view v1 as
select * from t1
union all
select * from t2;

Probably, but we don't support UNION in views before 7.1 :-(

I'm not real clear on why t1 and t2 are separate tables at all in this
example. Seems like making v1 be the real table, and t1 and t2 be
selective views of it, would work a lot easier.

regards, tom lane

#4(J.H.M. Dassen \(Ray\))
jdassen@cistron.nl
In reply to: Jaruwan Laongmal (#1)
Re: ask for help !!! (emergency case)

Jaruwan Laongmal <jaruwan@gits.net.th> wrote:

create view v1 as select * from t1,t2;
insert into v1 values(1,'wan1');

Quoting http://www.postgresql.org/docs/aw_pgsql_book/node149.html:
: Because views are not ordinary tables, INSERTs , UPDATEs , and DELETEs on
: views have no effect. The next section shows how rules can correct this
: problem.

HTH,
Ray
--
Pinky, Are You Pondering What I'm Pondering?
Ewww, I think so Brain, but I think I'd rather eat the Macarena.
Pinky and the Brain in "Plan Brain From Outer Space"