> I have 3 tables : appointment, appointment0 and
> appointment1.
>
> the fields of table "appointment" are as follows:
> noapp* (int4):ID Number of appointment (PK)
> custid (int4) : Customer ID
> salesid (int4) : Sales ID
> date(date) : Date of appointment
> time(time) : Time of appointment
> todo(char(150)) : What's to do with them
> done(char(1)): whether done (N/Y)
> warned (char(1)): whether warned with prompt
> timestamp (timestamp) : timestamp of record
>
> "appointment0" and "appointment1" have exactly the
> same field names as what "appointment" has.
>
> But...
> 1. the population of "appointment0" and "appointment1"
> are the subset of "appointment"
> 2. what the "appointment0" has are the members of
> "appointment" whose "Y" as the value of fieldname
> "done".
> 3. and what "appointmnet1" has are the members of
> "appointment" whose "N" as the value of fieldname
> "done".
>
> I want if my program inserted, updated, deleted the
> record of "appointment" than the postgres does the
> syncronization to the corresponded tables
> (appointment0 or appointment1 or both).
>
> Is it possible to implement this strategy with
> trigger? But how?
kalau mau, ngga perlu pakai trigger, tapi pake view
create view appointment0 as select * from appointment where done='Y';
create view appointment1 as select * from appointment where done='N';
ini detail nya
createdb tanyajawab
psql tanyajawab < /path/to/tanyajawab.txt
-- snip tanyajawab.txt --
drop view appointment0;
drop view appointment1;
drop table appointment;
create table appointment (
noapp integer,
custid integer,
salesid integer,
date date,
time time,
todo varchar,
done char(1),
warned char(1),
timestamp timestamp,
primary key(noapp)
);
insert into appointment values
('1','51','41',current_date,current_time,'fix this
1','Y','N',current_timestamp);
insert into appointment values
('2','52','41',current_date,current_time,'fix this
2','N','N',current_timestamp);
insert into appointment values
('3','53','41',current_date,current_time,'fix this
3','Y','N',current_timestamp);
insert into appointment values
('4','54','41',current_date,current_time,'fix this
4','N','N',current_timestamp);
insert into appointment values
('5','55','41',current_date,current_time,'fix this
5','Y','N',current_timestamp);
insert into appointment values
('6','56','15',current_date,current_time,'fix this
6','N','N',current_timestamp);
insert into appointment values
('7','57','15',current_date,current_time,'fix this
7','N','N',current_timestamp);
insert into appointment values
('8','58','15',current_date,current_time,'fix this
8','Y','N',current_timestamp);
insert into appointment values
('9','591','15',current_date,current_time,'fix this
9','N','N',current_timestamp);
insert into appointment values
('10','60','15',current_date,current_time,'fix this
10','N','N',current_timestamp);
create view appointment0 as select * from appointment where done='Y';
create view appointment1 as select * from appointment where done='N';
-- snap --
terus jalanin psql
test=# select * from appointment0;
noapp | custid | salesid |date| time |todo|
done | warned | timestamp
---++-++-++--++
1 | 51 | 41 | 2004-07-30 | 12:59:59.391426 | fix this 1 | Y
| N | 2004-07-30 12:59:59.391426
3 | 53 | 41 | 2004-07-30 | 12:59:59.398163 | fix this 3 | Y
| N | 2004-07-30 12:59:59.398163
5 | 55 | 41 | 2004-07-30 | 12:59:59.407393 | fix this 5 | Y
| N | 2004-07-30 12:59:59.407393
8 | 58 | 15 | 2004-07-30 | 12:59:59.424341 | fix this 8 | Y
| N | 2004-07-30 12:59:59.424341
(4 rows)
test=# delete from appointment where noapp=1;
DELETE 1
test=# update appointment set custid=99 where noapp=5;
UPDATE 1
test=# select * from appointment0;
noapp | custid | salesid |date| time |todo|
done | warned | timestamp
---++-++-++--++
3 | 53 | 41 | 2004-07-30 | 12:59:59.398163 | fix this 3 | Y
| N | 2004-07-30 12:59:59.398163
8 | 58 | 15 | 2004-07-30 | 12:59:59.424341 | fix this 8 | Y
| N | 2004-07-30 12:59:59.424341
5 | 99 | 41 | 2004-07-30 | 12:59:59.407393 | fix this 5 | Y
| N | 2004-07-30 12:59:59.407393
(3 rows)
--
Unsubscribe: kirim email kosong ke [EMAIL PROTECTED]
Arsip, FAQ, dan info milis di http://linux.or.id/milis.php
Tidak bisa posting? Baca:
http://linux.or.id/wiki/index.php?pagename=ProblemMilisDanSolusi
http://linux.or.id/wiki/index.php?pagename=TataTertibMilis