Temporary solution around inheritance/fireign key problem.

Temporary solution around inheritance/fireign key problem.

am 09.09.2004 02:22:15 von Vadim.Passynkov

Hello all!

I create a temporary solution to solve problem with
inheritance/fireign
key behavior and I want to share this solution with Postgres users.

I want to use this solution for my internal project.
and if somebody from the experts can review this I will appreciate.

I am not sure about validity of foreign_key_* functions which
provide the same functionality as RI_FKey*

Entire docs in postgresql_autodoc format here
http://www.pathcom.com/~pvi/pgsql_inherit_complete/

Entire test package here
http://www.pathcom.com/~pvi/pgsql_inherit_complete/pgsql_inh erit_complete.tgz

This is README file.

# $Id: README,v 1.3 2004/09/07 19:56:42 pvi Exp $

Architecture restrictions
~~~~~~~~~~~~~~~~~
1) if a table in the hierarchy has a primary key this key must be
surrogate
2) all tables in the same hierarchy must have the same source of
primary key.
in the example below there are following tables: table_a1, table_b,
table_c, table_bb,
table_bbb, "table cc", "table ccc" has the same source of
primary key - sequence table_a1_id_seq.
3) the surrogate key can not be generated by the user.

mydb=# INSERT INTO inherit_tests.table_a1 ( id, f_a1 ) VALUES ( 13,
'test1' );
ERROR: id is surrogate key, you can not generate it

instead the folliwng statement should be used:

mydb=# INSERT INTO inherit_tests.table_a1 ( f_a1 ) VALUES ( 'test1'
);
id
----
18
(1 row)
RULE get_pkey_on_insert will return generated primary key

4) due to the primary key is surrogate, only 'ON UPDATE NOACTION' is
supported.

Current implementation restrictions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1)
Primary key name must be 'id', it is hard coded.
This restriction exists until the problem with old.id in plpgsql
trigger
is not resolved.The trigger uses foreign_key_* functions. The problem
can be
solved by rewriting the functions on 'C','pltcl' etc.
How to resolve this problem using PLPGSQL I do not know.

2) SQL RULEs are not copy from base table to derived.

Object modificators
~~~~~~~~~~~~~~~~~~~
The package supports the following modificators:

private - applicable for triggers, indexes, foreign key constraints
abstract - applicable for tables
final - applicable for foreign key constraints

To use the modificators include '' tag into SQL comment
for database object. The package uses only the ' tag in
the
comment, all others words are ignored. The syntaxic of the comment
should
looks like:
COMMENT ON IS 'some stringsome other
string';

For example, the table 'common_system.accounting' is declared as
abstract.
mydb=# COMMENT ON TABLE common_system.accounting IS '
superclass';
mydb=# \dt+ common_system.accounting
List of relations
Schema | Name | Type | Owner | Description
---------------+------------+-------+----------+------------ ------------
common_system | accounting | table | truemail |
superclass
(1 row)

Example
~~~~~~~
The following example displays the usage of the package.

+----------------------+
| schema common_system |
+-----------------+----------------------+------------------ -----------+
|
|
| accounting ( abstract )
|
| |
|
| |
|
| I
|
| N foreign_key_*( )
|
| H
|
| E inherit_complete( )
|
| R
|
| I and some others util functions
|
| T
|
| |
|
| +------------------------------------+
|
| | / \
|
| | / \
|
+------------|---------------------------------/-----\------ -----------+
| +----------------------+ / \
| | schema inherit_tests | / \
+------------|----+----------------------+--/-----------\--- -----------+
| \ (schema inherit_tests) \
|
| \ / \
|
| table_a1<---------FK1(id - a1_id)----------table_d1
|
| / \ / / ^ \
|
| table_b table_c / table_e | table_f
|
| / \ | / | |
|
| table_bb table_bbb "table cc" / table_ee |
|
| | / | |
|
| "table ccc" / table_eee |
|
| / |
|
| +-/--------FK2(d1_id - id)--+
|
| |/
|
| table_g1
|
| / \
|
| table_h table_i
|
|
|
+----------------------------------------------------------- -----------+

FK1 - FOREIGN KEY (a1_id) REFERENCES inherit_tests.table_a1(id)
ON DELETE NOACTION ONUPDATE NOACTION

FK2 - FOREIGN KEY (d1_id) REFERENCES inherit_tests.table_d1(id)
ON DELETE CASCADE ONUPDATE NOACTION

To fix the current inconsistence of the PostgreSQL implementation of
inheritance
the following statement have to be run.
mydb=# SELECT common_system.inherit_complete();
The function should be executed after the
database schema creation, but before inserting data.

The inherit_complete function executes the following steps:

1) If table has a abstract modificator, the followng trigger is
created:
".abstract" BEFORE INSERT OR DELETE OR UPDATE ON

FOR EACH STATEMENT EXECUTE PROCEDURE
common_system.make_db_class_abstract()

2) If the base table has non-private index, create the same index for
all derived tables.

3) Drop the default value for primary key column for all tables in the
hierarchy.
The next trigger is created instead of the default value.

"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey(, )

4) The rule is created for returning the generated primary key

"_get_pkey_on_insert" AS ON INSERT TO
DO SELECT currval() AS id LIMIT 1

5) If the foreign key constraint in the base table dosn't have private
or final modificator,
it will be replaced to two constraint triggers on reftable.
On the original table the constraint check will be also created.
If the foreign key constraint in the base table has final modificator,
the same foreign key will be
created on the derived tables.

on the reftable create triggers
AFTER DELETE ON NOT DEFERRABLE
INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_(,

,
, )

AFTER UPDATE ON NOT DEFERRABLE
INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_upd(,
,
, )

on the original table
CHECK (common_system.foreign_key_check_ins_upd(,
, ))

6) Copy all triggers from base table that don't has modificator
private.

Table "common_system.accounting" before run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
Triggers:
accounting BEFORE INSERT OR UPDATE ON common_system.accounting FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()

Table "common_system.accounting" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
Triggers:
accounting BEFORE INSERT OR UPDATE ON common_system.accounting FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
"common_system.accounting.abstract" BEFORE INSERT OR DELETE OR
UPDATE ON common_system.accounting FOR EACH STATEMENT EXECUTE
PROCEDURE common_system.make_db_class_abstract()

Table "inherit_tests.table_a1" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_a1_id_seq'::text)
f_a1 | text |
Indexes:
"table_a1_pkey" primary key, btree (id)
Inherits: accounting

Table "inherit_tests.table_a1" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
f_a1 | text |
Indexes:
"table_a1_pkey" primary key, btree (id)
Rules:
"inherit_tests.table_a1_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_a1 DO SELECT
currval('inherit_tests.table_a1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_a1 FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_a1_id_seq')
"RI_ConstraintTrigger_71150" AFTER DELETE ON
inherit_tests.table_a1 NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_noaction_del('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
"RI_ConstraintTrigger_71151" AFTER UPDATE ON
inherit_tests.table_a1 NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_noaction_upd('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_a1 FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: accounting

Table "inherit_tests.table_b" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_a1_id_seq'::text)
f_a1 | text |
f_b | text |
Inherits: table_a1

Table "inherit_tests.table_b" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
f_a1 | text |
f_b | text |
Indexes:
"table_b_pkey" primary key, btree (id)
Rules:
"inherit_tests.table_b_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_b DO SELECT
currval('inherit_tests.table_a1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_b FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_a1_id_seq')
"RI_ConstraintTrigger_71276" AFTER DELETE ON inherit_tests.table_b
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_del('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
"RI_ConstraintTrigger_71277" AFTER UPDATE ON inherit_tests.table_b
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_upd('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_b FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_a1

Table "inherit_tests.table_c" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_a1_id_seq'::text)
f_a1 | text |
f_c | text |
Inherits: table_a1

Table "inherit_tests.table_c" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
f_a1 | text |
f_c | text |
Indexes:
"table_c_pkey" primary key, btree (id)
Rules:
"inherit_tests.table_c_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_c DO SELECT
currval('inherit_tests.table_a1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_c FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_a1_id_seq')
"RI_ConstraintTrigger_71300" AFTER DELETE ON inherit_tests.table_c
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_del('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
"RI_ConstraintTrigger_71301" AFTER UPDATE ON inherit_tests.table_c
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_upd('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_c FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_a1

Table "inherit_tests.table_bb" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_a1_id_seq'::text)
f_a1 | text |
f_b | text |
f_bb | text |
Inherits: table_b

Table "inherit_tests.table_bb" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
f_a1 | text |
f_b | text |
f_bb | text |
Indexes:
"table_bb_pkey" primary key, btree (id)
Rules:
"inherit_tests.table_bb_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_bb DO SELECT
currval('inherit_tests.table_a1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_bb FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_a1_id_seq')
"RI_ConstraintTrigger_71330" AFTER DELETE ON
inherit_tests.table_bb NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_noaction_del('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
"RI_ConstraintTrigger_71331" AFTER UPDATE ON
inherit_tests.table_bb NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_noaction_upd('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_bb FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_b

Table "inherit_tests.table_bbb" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_a1_id_seq'::text)
f_a1 | text |
f_b | text |
f_bbb | text |
Inherits: table_b

Table "inherit_tests.table_bbb" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
f_a1 | text |
f_b | text |
f_bbb | text |
Indexes:
"table_bbb_pkey" primary key, btree (id)
Rules:
"inherit_tests.table_bbb_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_bbb DO SELECT
currval('inherit_tests.table_a1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_bbb FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_a1_id_seq')
"RI_ConstraintTrigger_71322" AFTER DELETE ON
inherit_tests.table_bbb NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH
ROW EXECUTE PROCEDURE common_system.foreign_key_noaction_del('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
"RI_ConstraintTrigger_71323" AFTER UPDATE ON
inherit_tests.table_bbb NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH
ROW EXECUTE PROCEDURE common_system.foreign_key_noaction_upd('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_bbb FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_b

Table "inherit_tests.table cc" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_a1_id_seq'::text)
f_a1 | text |
f_c | text |
f_cc | text |
Inherits: table_c

Table "inherit_tests.table cc" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
f_a1 | text |
f_c | text |
f_cc | text |
Indexes:
"table cc_pkey" primary key, btree (id)
Rules:
"inherit_tests.""table cc""_get_pkey_on_insert" AS ON INSERT TO
inherit_tests."table cc" DO SELECT
currval('inherit_tests.table_a1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests."table cc" FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_a1_id_seq')
"RI_ConstraintTrigger_71342" AFTER DELETE ON inherit_tests."table
cc" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_del('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
"RI_ConstraintTrigger_71343" AFTER UPDATE ON inherit_tests."table
cc" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_upd('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests."table cc" FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_c

Table "inherit_tests.table ccc" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_a1_id_seq'::text)
f_a1 | text |
f_c | text |
f_cc | text |
f_ccc | text |
Inherits: table cc

Table "inherit_tests.table ccc" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
f_a1 | text |
f_c | text |
f_cc | text |
f_ccc | text |
Indexes:
"table ccc_pkey" primary key, btree (id)
Rules:
"inherit_tests.""table ccc""_get_pkey_on_insert" AS ON INSERT TO
inherit_tests."table ccc" DO SELECT
currval('inherit_tests.table_a1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests."table ccc" FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_a1_id_seq')
"RI_ConstraintTrigger_71368" AFTER DELETE ON inherit_tests."table
ccc" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_del('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
"RI_ConstraintTrigger_71369" AFTER UPDATE ON inherit_tests."table
ccc" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_upd('test01',
'inherit_tests.table_d1', 'a1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests."table ccc"
FOR EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table cc


Table "inherit_tests.table_d1" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_d1_id_seq'::text)
a1_id | integer | not null
f_d1 | text |
Indexes:
"table_d1_pkey" primary key, btree (id)
Foreign-key constraints:
"test01" FOREIGN KEY (a1_id) REFERENCES inherit_tests.table_a1(id)
Inherits: accounting

Table "inherit_tests.table_d1" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
a1_id | integer | not null
f_d1 | text |
Indexes:
"table_d1_pkey" primary key, btree (id)
Check constraints:
"test01" CHECK (common_system.foreign_key_check_ins_upd(a1_id,
'inherit_tests.table_a1'::text, 'id'::name))
Rules:
"inherit_tests.table_d1_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_d1 DO SELECT
currval('inherit_tests.table_d1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_d1 FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_d1_id_seq')
"RI_ConstraintTrigger_71153" AFTER DELETE ON
inherit_tests.table_d1 NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_cascade_del('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
"RI_ConstraintTrigger_71154" AFTER UPDATE ON
inherit_tests.table_d1 NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_noaction_upd('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_d1 FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: accounting


Table "inherit_tests.table_e" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_d1_id_seq'::text)
a1_id | integer | not null
f_d1 | text |
f_e | text |
Inherits: table_d1

Table "inherit_tests.table_e" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
a1_id | integer | not null
f_d1 | text |
f_e | text |
Indexes:
"table_e_pkey" primary key, btree (id)
Check constraints:
"test01" CHECK (common_system.foreign_key_check_ins_upd(a1_id,
'inherit_tests.table_a1'::text, 'id'::name))
Rules:
"inherit_tests.table_e_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_e DO SELECT
currval('inherit_tests.table_d1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_e FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_d1_id_seq')
"RI_ConstraintTrigger_71260" AFTER DELETE ON inherit_tests.table_e
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_cascade_del('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
"RI_ConstraintTrigger_71261" AFTER UPDATE ON inherit_tests.table_e
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_upd('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_e FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_d1


Table "inherit_tests.table_f" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_d1_id_seq'::text)
a1_id | integer | not null
f_d1 | text |
f_f | text |
Inherits: table_d1

Table "inherit_tests.table_f" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
a1_id | integer | not null
f_d1 | text |
f_f | text |
Indexes:
"table_f_pkey" primary key, btree (id)
Check constraints:
"test01" CHECK (common_system.foreign_key_check_ins_upd(a1_id,
'inherit_tests.table_a1'::text, 'id'::name))
Rules:
"inherit_tests.table_f_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_f DO SELECT
currval('inherit_tests.table_d1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_f FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_d1_id_seq')
"RI_ConstraintTrigger_71304" AFTER DELETE ON inherit_tests.table_f
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_cascade_del('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
"RI_ConstraintTrigger_71305" AFTER UPDATE ON inherit_tests.table_f
NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE
common_system.foreign_key_noaction_upd('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_f FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_d1

Table "inherit_tests.table_ee" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_d1_id_seq'::text)
a1_id | integer | not null
f_d1 | text |
f_e | text |
f_ee | text |
Inherits: table_e

Table "inherit_tests.table_ee" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
a1_id | integer | not null
f_d1 | text |
f_e | text |
f_ee | text |
Indexes:
"table_ee_pkey" primary key, btree (id)
Rules:
"inherit_tests.table_ee_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_ee DO SELECT
currval('inherit_tests.table_d1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_ee FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_d1_id_seq')
"RI_ConstraintTrigger_71326" AFTER DELETE ON
inherit_tests.table_ee NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_cascade_del('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
"RI_ConstraintTrigger_71327" AFTER UPDATE ON
inherit_tests.table_ee NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
EXECUTE PROCEDURE common_system.foreign_key_noaction_upd('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_ee FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_e

Table "inherit_tests.table_eee" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_d1_id_seq'::text)
a1_id | integer | not null
f_d1 | text |
f_e | text |
f_ee | text |
f_eee | text |
Inherits: table_ee

Table "inherit_tests.table_eee" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
a1_id | integer | not null
f_d1 | text |
f_e | text |
f_ee | text |
f_eee | text |
Indexes:
"table_eee_pkey" primary key, btree (id)
Rules:
"inherit_tests.table_eee_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_eee DO SELECT
currval('inherit_tests.table_d1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_eee FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_d1_id_seq')
"RI_ConstraintTrigger_71346" AFTER DELETE ON
inherit_tests.table_eee NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH
ROW EXECUTE PROCEDURE common_system.foreign_key_cascade_del('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
"RI_ConstraintTrigger_71347" AFTER UPDATE ON
inherit_tests.table_eee NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH
ROW EXECUTE PROCEDURE common_system.foreign_key_noaction_upd('test02',
'inherit_tests.table_g1', 'd1_id', 'id')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_eee FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_ee

Table "inherit_tests.table_g1" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_g1_id_seq'::text)
d1_id | integer | not null
f_g1 | text |
Indexes:
"table_g1_pkey" primary key, btree (id)
Foreign-key constraints:
"test02" FOREIGN KEY (d1_id) REFERENCES inherit_tests.table_d1(id)
ON DELETE CASCADE
Inherits: accounting

Table "inherit_tests.table_g1" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
d1_id | integer | not null
f_g1 | text |
Indexes:
"table_g1_pkey" primary key, btree (id)
Check constraints:
"test02" CHECK (common_system.foreign_key_check_ins_upd(d1_id,
'inherit_tests.table_d1'::text, 'id'::name))
Rules:
"inherit_tests.table_g1_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_g1 DO SELECT
currval('inherit_tests.table_g1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_g1 FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_g1_id_seq')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_g1 FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: accounting


Table "inherit_tests.table_h" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_g1_id_seq'::text)
d1_id | integer | not null
f_g1 | text |
f_h | text |
Inherits: table_g1

Table "inherit_tests.table_h" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
d1_id | integer | not null
f_g1 | text |
f_h | text |
Indexes:
"table_h_pkey" primary key, btree (id)
Check constraints:
"test02" CHECK (common_system.foreign_key_check_ins_upd(d1_id,
'inherit_tests.table_d1'::text, 'id'::name))
Rules:
"inherit_tests.table_h_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_h DO SELECT
currval('inherit_tests.table_g1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_h FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_g1_id_seq')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_h FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_g1


Table "inherit_tests.table_i" before run inherit_complete
Column | Type |
Modifiers
--------------+-----------------------------+--------------- --------------------------------------------------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null default
nextval('inherit_tests.table_g1_id_seq'::text)
d1_id | integer | not null
f_g1 | text |
f_i | text |
Inherits: table_g1

Table "inherit_tests.table_i" after run inherit_complete
Column | Type | Modifiers
--------------+-----------------------------+-----------
create_on | timestamp without time zone | not null
modify_on | timestamp without time zone | not null
id | integer | not null
d1_id | integer | not null
f_g1 | text |
f_i | text |
Indexes:
"table_i_pkey" primary key, btree (id)
Check constraints:
"test02" CHECK (common_system.foreign_key_check_ins_upd(d1_id,
'inherit_tests.table_d1'::text, 'id'::name))
Rules:
"inherit_tests.table_i_get_pkey_on_insert" AS ON INSERT TO
inherit_tests.table_i DO SELECT
currval('inherit_tests.table_g1_id_seq'::text) AS id LIMIT 1
Triggers:
"01_protect_surrogate_pkey" BEFORE INSERT OR UPDATE ON
inherit_tests.table_i FOR EACH ROW EXECUTE PROCEDURE
common_system.protect_surrogate_pkey('id',
'inherit_tests.table_g1_id_seq')
accounting BEFORE INSERT OR UPDATE ON inherit_tests.table_i FOR
EACH ROW EXECUTE PROCEDURE common_system.accounting()
Inherits: table_g1

--
Vadim.Passynkov@pathcom.com