| 1 |
CREATE EXTENSION autoinc; |
| 2 |
|
| 3 |
create sequence aitest_seq increment 10 start 0 minvalue 0; |
| 4 |
|
| 5 |
create table aitest ( |
| 6 |
price_id int4, |
| 7 |
price_val int4, |
| 8 |
price_on int4 |
| 9 |
); |
| 10 |
|
| 11 |
create trigger aiserial |
| 12 |
before insert or update on aitest |
| 13 |
for each row |
| 14 |
execute procedure |
| 15 |
autoinc (price_on, aitest_seq); |
| 16 |
|
| 17 |
insert into aitest values (1, 1, null); |
| 18 |
insert into aitest values (2, 2, 0); |
| 19 |
insert into aitest values (3, 3, 1); |
| 20 |
|
| 21 |
select * from aitest; |
| 22 |
|
| 23 |
update aitest set price_on = 11; |
| 24 |
|
| 25 |
select * from aitest; |
| 26 |
|
| 27 |
update aitest set price_on = 0; |
| 28 |
|
| 29 |
select * from aitest; |
| 30 |
|
| 31 |
update aitest set price_on = null; |
| 32 |
|
| 33 |
select * from aitest; |