tbl_ins_test.sct

application/octet-stream

Filename: tbl_ins_test.sct
Type: application/octet-stream
Part: 0
Message: Rules for Inserting Serials
Script started on Fri Feb 16 13:21:04 2001
[root@bxxxxx pgsql]# createdb tblinstest
CREATE DATABASE
[root@bxxxxx pgsql]# psql -eq tblinstest <ins_rule_test.sql
create table tbl(id serial PRIMARY KEY,tx text);
NOTICE:  CREATE TABLE will create implicit sequence 'tbl_id_seq' for SERIAL column 'tbl.id'
NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index 'tbl_pkey' for table 'tbl'
create table tbl_log(lid serial PRIMARY KEY,nid int4,ntx text);
NOTICE:  CREATE TABLE will create implicit sequence 'tbl_log_lid_seq' for SERIAL column 'tbl_log.lid'
NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index 'tbl_log_pkey' for table 'tbl_log'
create rule tblins AS ON insert to tbl do insert into tbl_log (nid,ntx) VALUES (new.*);
insert into tbl (tx) Values ('This');
insert into tbl (tx) Values ('is a');
insert into tbl (tx) values ('test');
select * from tbl;
 id |  tx  
----+------
  2 | This
  4 | is a
  6 | test
(3 rows)

select * from tbl_log;
 lid | nid | ntx  
-----+-----+------
   1 |   1 | This
   2 |   3 | is a
   3 |   5 | test
(3 rows)

insert into tbl (tx) select tx from tbl;
select * from tbl;
 id |  tx  
----+------
  2 | This
  4 | is a
  6 | test
 10 | This
 11 | is a
 12 | test
(6 rows)

select * from tbl_log;
 lid | nid | ntx  
-----+-----+------
   1 |   1 | This
   2 |   3 | is a
   3 |   5 | test
   4 |   7 | This
   5 |   8 | is a
   6 |   9 | test
(6 rows)

[root@bxxxxx pgsql]# dropdb tblinstest
DROP DATABASE
[root@bxxxxx pgsql]# exit

Script done on Fri Feb 16 13:22:02 2001