Commit 96b00c43 authored by Peter Eisentraut's avatar Peter Eisentraut

Remove obsolete pg_constraint.consrc column

This has been deprecated and effectively unused for a long time.
Reviewed-by: default avatarDaniel Gustafsson <daniel@yesql.se>
parent fe503823
...@@ -2400,14 +2400,10 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l ...@@ -2400,14 +2400,10 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
<entry><structfield>conbin</structfield></entry> <entry><structfield>conbin</structfield></entry>
<entry><type>pg_node_tree</type></entry> <entry><type>pg_node_tree</type></entry>
<entry></entry> <entry></entry>
<entry>If a check constraint, an internal representation of the expression</entry> <entry>If a check constraint, an internal representation of the
</row> expression. (It's recommended to use
<function>pg_get_constraintdef()</function> to extract the definition of
<row> a check constraint.)</entry>
<entry><structfield>consrc</structfield></entry>
<entry><type>text</type></entry>
<entry></entry>
<entry>If a check constraint, a human-readable representation of the expression</entry>
</row> </row>
</tbody> </tbody>
</tgroup> </tgroup>
...@@ -2423,15 +2419,6 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l ...@@ -2423,15 +2419,6 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
index.) index.)
</para> </para>
<note>
<para>
<structfield>consrc</structfield> is not updated when referenced objects
change; for example, it won't track renaming of columns. Rather than
relying on this field, it's best to use <function>pg_get_constraintdef()</function>
to extract the definition of a check constraint.
</para>
</note>
<note> <note>
<para> <para>
<literal>pg_class.relchecks</literal> needs to agree with the <literal>pg_class.relchecks</literal> needs to agree with the
......
...@@ -2315,7 +2315,6 @@ StoreRelCheck(Relation rel, const char *ccname, Node *expr, ...@@ -2315,7 +2315,6 @@ StoreRelCheck(Relation rel, const char *ccname, Node *expr,
bool is_no_inherit, bool is_internal) bool is_no_inherit, bool is_internal)
{ {
char *ccbin; char *ccbin;
char *ccsrc;
List *varList; List *varList;
int keycount; int keycount;
int16 *attNos; int16 *attNos;
...@@ -2326,14 +2325,6 @@ StoreRelCheck(Relation rel, const char *ccname, Node *expr, ...@@ -2326,14 +2325,6 @@ StoreRelCheck(Relation rel, const char *ccname, Node *expr,
*/ */
ccbin = nodeToString(expr); ccbin = nodeToString(expr);
/*
* Also deparse it to form the mostly-obsolete consrc field.
*/
ccsrc = deparse_expression(expr,
deparse_context_for(RelationGetRelationName(rel),
RelationGetRelid(rel)),
false, false);
/* /*
* Find columns of rel that are used in expr * Find columns of rel that are used in expr
* *
...@@ -2406,14 +2397,12 @@ StoreRelCheck(Relation rel, const char *ccname, Node *expr, ...@@ -2406,14 +2397,12 @@ StoreRelCheck(Relation rel, const char *ccname, Node *expr,
NULL, /* not an exclusion constraint */ NULL, /* not an exclusion constraint */
expr, /* Tree form of check constraint */ expr, /* Tree form of check constraint */
ccbin, /* Binary form of check constraint */ ccbin, /* Binary form of check constraint */
ccsrc, /* Source form of check constraint */
is_local, /* conislocal */ is_local, /* conislocal */
inhcount, /* coninhcount */ inhcount, /* coninhcount */
is_no_inherit, /* connoinherit */ is_no_inherit, /* connoinherit */
is_internal); /* internally constructed? */ is_internal); /* internally constructed? */
pfree(ccbin); pfree(ccbin);
pfree(ccsrc);
return constrOid; return constrOid;
} }
......
...@@ -1336,7 +1336,6 @@ index_constraint_create(Relation heapRelation, ...@@ -1336,7 +1336,6 @@ index_constraint_create(Relation heapRelation,
indexInfo->ii_ExclusionOps, indexInfo->ii_ExclusionOps,
NULL, /* no check constraint */ NULL, /* no check constraint */
NULL, NULL,
NULL,
islocal, islocal,
inhcount, inhcount,
noinherit, noinherit,
......
...@@ -78,7 +78,6 @@ CreateConstraintEntry(const char *constraintName, ...@@ -78,7 +78,6 @@ CreateConstraintEntry(const char *constraintName,
const Oid *exclOp, const Oid *exclOp,
Node *conExpr, Node *conExpr,
const char *conBin, const char *conBin,
const char *conSrc,
bool conIsLocal, bool conIsLocal,
int conInhCount, int conInhCount,
bool conNoInherit, bool conNoInherit,
...@@ -218,22 +217,11 @@ CreateConstraintEntry(const char *constraintName, ...@@ -218,22 +217,11 @@ CreateConstraintEntry(const char *constraintName,
else else
nulls[Anum_pg_constraint_conexclop - 1] = true; nulls[Anum_pg_constraint_conexclop - 1] = true;
/*
* initialize the binary form of the check constraint.
*/
if (conBin) if (conBin)
values[Anum_pg_constraint_conbin - 1] = CStringGetTextDatum(conBin); values[Anum_pg_constraint_conbin - 1] = CStringGetTextDatum(conBin);
else else
nulls[Anum_pg_constraint_conbin - 1] = true; nulls[Anum_pg_constraint_conbin - 1] = true;
/*
* initialize the text form of the check constraint
*/
if (conSrc)
values[Anum_pg_constraint_consrc - 1] = CStringGetTextDatum(conSrc);
else
nulls[Anum_pg_constraint_consrc - 1] = true;
tup = heap_form_tuple(RelationGetDescr(conDesc), values, nulls); tup = heap_form_tuple(RelationGetDescr(conDesc), values, nulls);
conOid = CatalogTupleInsert(conDesc, tup); conOid = CatalogTupleInsert(conDesc, tup);
...@@ -703,7 +691,6 @@ clone_fk_constraints(Relation pg_constraint, Relation parentRel, ...@@ -703,7 +691,6 @@ clone_fk_constraints(Relation pg_constraint, Relation parentRel,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL,
false, false,
1, false, true); 1, false, true);
subclone = lappend_oid(subclone, constrOid); subclone = lappend_oid(subclone, constrOid);
......
...@@ -7704,7 +7704,6 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, ...@@ -7704,7 +7704,6 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
NULL, /* no exclusion constraint */ NULL, /* no exclusion constraint */
NULL, /* no check constraint */ NULL, /* no check constraint */
NULL, NULL,
NULL,
true, /* islocal */ true, /* islocal */
0, /* inhcount */ 0, /* inhcount */
true, /* isnoinherit */ true, /* isnoinherit */
......
...@@ -752,7 +752,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, ...@@ -752,7 +752,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
NULL, /* no exclusion */ NULL, /* no exclusion */
NULL, /* no check constraint */ NULL, /* no check constraint */
NULL, NULL,
NULL,
true, /* islocal */ true, /* islocal */
0, /* inhcount */ 0, /* inhcount */
true, /* isnoinherit */ true, /* isnoinherit */
......
...@@ -3042,7 +3042,6 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, ...@@ -3042,7 +3042,6 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
const char *domainName, ObjectAddress *constrAddr) const char *domainName, ObjectAddress *constrAddr)
{ {
Node *expr; Node *expr;
char *ccsrc;
char *ccbin; char *ccbin;
ParseState *pstate; ParseState *pstate;
CoerceToDomainValue *domVal; CoerceToDomainValue *domVal;
...@@ -3116,12 +3115,6 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, ...@@ -3116,12 +3115,6 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
*/ */
ccbin = nodeToString(expr); ccbin = nodeToString(expr);
/*
* Deparse it to produce text for consrc.
*/
ccsrc = deparse_expression(expr,
NIL, false, false);
/* /*
* Store the constraint in pg_constraint * Store the constraint in pg_constraint
*/ */
...@@ -3151,7 +3144,6 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, ...@@ -3151,7 +3144,6 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
NULL, /* not an exclusion constraint */ NULL, /* not an exclusion constraint */
expr, /* Tree form of check constraint */ expr, /* Tree form of check constraint */
ccbin, /* Binary form of check constraint */ ccbin, /* Binary form of check constraint */
ccsrc, /* Source form of check constraint */
true, /* is local */ true, /* is local */
0, /* inhcount */ 0, /* inhcount */
false, /* connoinherit */ false, /* connoinherit */
......
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 201811011 #define CATALOG_VERSION_NO 201811012
#endif #endif
...@@ -142,11 +142,6 @@ CATALOG(pg_constraint,2606,ConstraintRelationId) ...@@ -142,11 +142,6 @@ CATALOG(pg_constraint,2606,ConstraintRelationId)
* If a check constraint, nodeToString representation of expression * If a check constraint, nodeToString representation of expression
*/ */
pg_node_tree conbin; pg_node_tree conbin;
/*
* If a check constraint, source-text representation of expression
*/
text consrc;
#endif #endif
} FormData_pg_constraint; } FormData_pg_constraint;
...@@ -224,7 +219,6 @@ extern Oid CreateConstraintEntry(const char *constraintName, ...@@ -224,7 +219,6 @@ extern Oid CreateConstraintEntry(const char *constraintName,
const Oid *exclOp, const Oid *exclOp,
Node *conExpr, Node *conExpr,
const char *conBin, const char *conBin,
const char *conSrc,
bool conIsLocal, bool conIsLocal,
int conInhCount, int conInhCount,
bool conNoInherit, bool conNoInherit,
......
...@@ -797,7 +797,7 @@ drop table p1; ...@@ -797,7 +797,7 @@ drop table p1;
CREATE TABLE ac (aa TEXT); CREATE TABLE ac (aa TEXT);
alter table ac add constraint ac_check check (aa is not null); alter table ac add constraint ac_check check (aa is not null);
CREATE TABLE bc (bb TEXT) INHERITS (ac); CREATE TABLE bc (bb TEXT) INHERITS (ac);
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+----------+---------+------------+-------------+------------------ ---------+----------+---------+------------+-------------+------------------
ac | ac_check | c | t | 0 | (aa IS NOT NULL) ac | ac_check | c | t | 0 | (aa IS NOT NULL)
...@@ -813,14 +813,14 @@ DETAIL: Failing row contains (null, null). ...@@ -813,14 +813,14 @@ DETAIL: Failing row contains (null, null).
alter table bc drop constraint ac_check; -- fail, disallowed alter table bc drop constraint ac_check; -- fail, disallowed
ERROR: cannot drop inherited constraint "ac_check" of relation "bc" ERROR: cannot drop inherited constraint "ac_check" of relation "bc"
alter table ac drop constraint ac_check; alter table ac drop constraint ac_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+---------+---------+------------+-------------+-------- ---------+---------+---------+------------+-------------+--------
(0 rows) (0 rows)
-- try the unnamed-constraint case -- try the unnamed-constraint case
alter table ac add check (aa is not null); alter table ac add check (aa is not null);
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+-------------+---------+------------+-------------+------------------ ---------+-------------+---------+------------+-------------+------------------
ac | ac_aa_check | c | t | 0 | (aa IS NOT NULL) ac | ac_aa_check | c | t | 0 | (aa IS NOT NULL)
...@@ -836,14 +836,14 @@ DETAIL: Failing row contains (null, null). ...@@ -836,14 +836,14 @@ DETAIL: Failing row contains (null, null).
alter table bc drop constraint ac_aa_check; -- fail, disallowed alter table bc drop constraint ac_aa_check; -- fail, disallowed
ERROR: cannot drop inherited constraint "ac_aa_check" of relation "bc" ERROR: cannot drop inherited constraint "ac_aa_check" of relation "bc"
alter table ac drop constraint ac_aa_check; alter table ac drop constraint ac_aa_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+---------+---------+------------+-------------+-------- ---------+---------+---------+------------+-------------+--------
(0 rows) (0 rows)
alter table ac add constraint ac_check check (aa is not null); alter table ac add constraint ac_check check (aa is not null);
alter table bc no inherit ac; alter table bc no inherit ac;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+----------+---------+------------+-------------+------------------ ---------+----------+---------+------------+-------------+------------------
ac | ac_check | c | t | 0 | (aa IS NOT NULL) ac | ac_check | c | t | 0 | (aa IS NOT NULL)
...@@ -851,14 +851,14 @@ select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg ...@@ -851,14 +851,14 @@ select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg
(2 rows) (2 rows)
alter table bc drop constraint ac_check; alter table bc drop constraint ac_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+----------+---------+------------+-------------+------------------ ---------+----------+---------+------------+-------------+------------------
ac | ac_check | c | t | 0 | (aa IS NOT NULL) ac | ac_check | c | t | 0 | (aa IS NOT NULL)
(1 row) (1 row)
alter table ac drop constraint ac_check; alter table ac drop constraint ac_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+---------+---------+------------+-------------+-------- ---------+---------+---------+------------+-------------+--------
(0 rows) (0 rows)
...@@ -869,7 +869,7 @@ create table ac (a int constraint check_a check (a <> 0)); ...@@ -869,7 +869,7 @@ create table ac (a int constraint check_a check (a <> 0));
create table bc (a int constraint check_a check (a <> 0), b int constraint check_b check (b <> 0)) inherits (ac); create table bc (a int constraint check_a check (a <> 0), b int constraint check_b check (b <> 0)) inherits (ac);
NOTICE: merging column "a" with inherited definition NOTICE: merging column "a" with inherited definition
NOTICE: merging constraint "check_a" with inherited definition NOTICE: merging constraint "check_a" with inherited definition
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+---------+---------+------------+-------------+---------- ---------+---------+---------+------------+-------------+----------
ac | check_a | c | t | 0 | (a <> 0) ac | check_a | c | t | 0 | (a <> 0)
...@@ -882,7 +882,7 @@ drop table ac; ...@@ -882,7 +882,7 @@ drop table ac;
create table ac (a int constraint check_a check (a <> 0)); create table ac (a int constraint check_a check (a <> 0));
create table bc (b int constraint check_b check (b <> 0)); create table bc (b int constraint check_b check (b <> 0));
create table cc (c int constraint check_c check (c <> 0)) inherits (ac, bc); create table cc (c int constraint check_c check (c <> 0)) inherits (ac, bc);
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+---------+---------+------------+-------------+---------- ---------+---------+---------+------------+-------------+----------
ac | check_a | c | t | 0 | (a <> 0) ac | check_a | c | t | 0 | (a <> 0)
...@@ -893,7 +893,7 @@ select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg ...@@ -893,7 +893,7 @@ select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg
(5 rows) (5 rows)
alter table cc no inherit bc; alter table cc no inherit bc;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2;
relname | conname | contype | conislocal | coninhcount | consrc relname | conname | contype | conislocal | coninhcount | consrc
---------+---------+---------+------------+-------------+---------- ---------+---------+---------+------------+-------------+----------
ac | check_a | c | t | 0 | (a <> 0) ac | check_a | c | t | 0 | (a <> 0)
......
...@@ -257,40 +257,40 @@ drop table p1; ...@@ -257,40 +257,40 @@ drop table p1;
CREATE TABLE ac (aa TEXT); CREATE TABLE ac (aa TEXT);
alter table ac add constraint ac_check check (aa is not null); alter table ac add constraint ac_check check (aa is not null);
CREATE TABLE bc (bb TEXT) INHERITS (ac); CREATE TABLE bc (bb TEXT) INHERITS (ac);
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
insert into ac (aa) values (NULL); insert into ac (aa) values (NULL);
insert into bc (aa) values (NULL); insert into bc (aa) values (NULL);
alter table bc drop constraint ac_check; -- fail, disallowed alter table bc drop constraint ac_check; -- fail, disallowed
alter table ac drop constraint ac_check; alter table ac drop constraint ac_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
-- try the unnamed-constraint case -- try the unnamed-constraint case
alter table ac add check (aa is not null); alter table ac add check (aa is not null);
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
insert into ac (aa) values (NULL); insert into ac (aa) values (NULL);
insert into bc (aa) values (NULL); insert into bc (aa) values (NULL);
alter table bc drop constraint ac_aa_check; -- fail, disallowed alter table bc drop constraint ac_aa_check; -- fail, disallowed
alter table ac drop constraint ac_aa_check; alter table ac drop constraint ac_aa_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
alter table ac add constraint ac_check check (aa is not null); alter table ac add constraint ac_check check (aa is not null);
alter table bc no inherit ac; alter table bc no inherit ac;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
alter table bc drop constraint ac_check; alter table bc drop constraint ac_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
alter table ac drop constraint ac_check; alter table ac drop constraint ac_check;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
drop table bc; drop table bc;
drop table ac; drop table ac;
create table ac (a int constraint check_a check (a <> 0)); create table ac (a int constraint check_a check (a <> 0));
create table bc (a int constraint check_a check (a <> 0), b int constraint check_b check (b <> 0)) inherits (ac); create table bc (a int constraint check_a check (a <> 0), b int constraint check_b check (b <> 0)) inherits (ac);
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
drop table bc; drop table bc;
drop table ac; drop table ac;
...@@ -298,10 +298,10 @@ drop table ac; ...@@ -298,10 +298,10 @@ drop table ac;
create table ac (a int constraint check_a check (a <> 0)); create table ac (a int constraint check_a check (a <> 0));
create table bc (b int constraint check_b check (b <> 0)); create table bc (b int constraint check_b check (b <> 0));
create table cc (c int constraint check_c check (c <> 0)) inherits (ac, bc); create table cc (c int constraint check_c check (c <> 0)) inherits (ac, bc);
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2;
alter table cc no inherit bc; alter table cc no inherit bc;
select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2; select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2;
drop table cc; drop table cc;
drop table bc; drop table bc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment