Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace function trigf1() returns trigger as $$
- begin
- if (ballotbox.totvoters>votes.nofvotes) then
- raise notice 'more voters than allowed';
- return old;
- else return new;
- end if;
- end;
- $$ language plpgsql;
- create trigger T1
- Before insert or update on votes
- for each row
- execute procedure trigf1();
- ERROR: missing FROM-clause entry for table "ballotbox"
- LINE 1: SELECT (ballotbox.totvoters > votes.nofvotes)
- ^
- QUERY: SELECT (ballotbox.totvoters > votes.nofvotes)
- CONTEXT: PL/pgSQL function trigf1() line 3 at IF
- create table ballotBox
- (bno integer,
- cid numeric(4,0),
- street varchar(20),
- hno integer,
- totvoters integer,
- primary key (bno),
- foreign key (cid) references city);
- create table votes
- (cid numeric(4,0),
- bno integer,
- pid numeric(3,0),
- nofvotes integer,
- foreign key (cid) references city,
- foreign key (bno) references ballotBox,
- foreign key (pid) references party,
- check (nofvotes >= 0));
- insert into ballotBox values
- (1, 1, 'street1', 10, 1500),
- (2, 1, 'street2', 15, 490),
- (3, 1, 'street2', 15, 610),
- (4, 1, 'street2', 15, 650),
- (5, 2, 'street3', 10, 900),
- (6, 2, 'street3', 55, 800),
- (7, 2, 'street4', 67, 250),
- (8, 2, 'street4', 67, 990),
- (9, 2, 'street5', 5, 600),
- (10, 3, 'street1', 72, 1000),
- (11, 3, 'street6', 25, 610),
- (12, 3, 'street6', 25, 600),
- (13, 4, 'street2', 3, 550),
- (14, 4, 'street7', 15, 500),
- (15, 5, 'street8', 44, 1100),
- (16, 5, 'street9', 7, 710),
- (17, 5, 'street10', 13, 950);
- insert into votes values
- (1, 1, 200, 100),
- (1, 1, 210, 220),
- (1, 1, 220, 2),
- (1, 1, 230, 400),
- (1, 1, 240, 313),
- (1, 1, 250, 99),
- (2, 1, 200, 55),
- (2, 1, 210, 150),
- (2, 1, 220, 2),
- (2, 1, 230, 16),
- (2, 1, 240, 210);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement