Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b0422b2

Browse files
committed
Preliminary code review for domain CHECK constraints patch: add documentation,
make VALUE a non-reserved word again, use less invasive method of passing ConstraintTestValue into transformExpr, fix problems with nested constraint testing, do correct thing with NULL result from a constraint expression, remove memory leak. Domain checks still need much more work if we are going to allow ALTER DOMAIN, however.
1 parent ff73496 commit b0422b2

28 files changed

+222
-292
lines changed

doc/src/sgml/ref/create_domain.sgml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.8 2002/11/21 23:34:43 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.9 2002/12/12 20:35:07 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -30,7 +30,7 @@ CREATE DOMAIN <replaceable class="parameter">domainname</replaceable> [AS] <repl
3030
where <replaceable class="PARAMETER">constraint</replaceable> is:
3131

3232
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
33-
{ NOT NULL | NULL }
33+
{ NOT NULL | NULL | CHECK (<replaceable class="PARAMETER">expression</replaceable>) }
3434
</synopsis>
3535

3636
<refsect2 id="R2-SQL-CREATEDOMAIN-1">
@@ -128,6 +128,25 @@ where <replaceable class="PARAMETER">constraint</replaceable> is:
128128
</listitem>
129129
</varlistentry>
130130

131+
<varlistentry>
132+
<term><literal>CHECK (<replaceable class="PARAMETER">expression</replaceable>)</literal></term>
133+
<listitem>
134+
<para>
135+
<literal>CHECK</> clauses specify integrity constraints or tests
136+
which values of the domain must satisfy.
137+
Each constraint must be an expression
138+
producing a Boolean result. It should use the name <literal>VALUE</>
139+
to refer to the value being tested.
140+
</para>
141+
142+
<para>
143+
Currently, <literal>CHECK</literal> expressions cannot contain
144+
subselects nor refer to variables other than <literal>VALUE</>.
145+
</para>
146+
147+
</listitem>
148+
</varlistentry>
149+
131150
</variablelist>
132151
</para>
133152
</refsect2>

doc/src/sgml/release.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.168 2002/11/26 22:04:03 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.169 2002/12/12 20:35:07 tgl Exp $
33
-->
44

55
<appendix id="release">
@@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without
2424
worries about funny characters.
2525
-->
2626
<literallayout><![CDATA[
27+
Domains now support CHECK constraints
2728
]]></literallayout>
2829

2930
</sect1>

src/backend/catalog/heap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.236 2002/12/12 15:49:23 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.237 2002/12/12 20:35:08 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1567,7 +1567,7 @@ AddRelationRawConstraints(Relation rel,
15671567
/*
15681568
* Transform raw parsetree to executable expression.
15691569
*/
1570-
expr = transformExpr(pstate, cdef->raw_expr, NULL);
1570+
expr = transformExpr(pstate, cdef->raw_expr);
15711571

15721572
/*
15731573
* Make sure it yields a boolean result.
@@ -1691,7 +1691,7 @@ cookDefault(ParseState *pstate,
16911691
/*
16921692
* Transform raw parsetree to executable expression.
16931693
*/
1694-
expr = transformExpr(pstate, raw_default, NULL);
1694+
expr = transformExpr(pstate, raw_default);
16951695

16961696
/*
16971697
* Make sure default expr does not refer to any vars.

src/backend/catalog/pg_constraint.c

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.11 2002/12/06 05:00:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.12 2002/12/12 20:35:11 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -439,18 +439,16 @@ RemoveConstraintById(Oid conId)
439439
con = (Form_pg_constraint) GETSTRUCT(tup);
440440

441441
/*
442-
* If the constraint is for a relation, open and exclusive-lock
443-
* the relation it's for.
444-
*
445-
* If the constraint is for a domain, open and lock the pg_type entry
446-
* tye constraint is used on.
447-
*
448-
* XXX not clear what we should lock, if anything, for assert constraints.
442+
* Special processing depending on what the constraint is for.
449443
*/
450444
if (OidIsValid(con->conrelid))
451445
{
452446
Relation rel;
453447

448+
/*
449+
* If the constraint is for a relation, open and exclusive-lock the
450+
* relation it's for.
451+
*/
454452
rel = heap_open(con->conrelid, AccessExclusiveLock);
455453

456454
/*
@@ -490,34 +488,14 @@ RemoveConstraintById(Oid conId)
490488
/* Keep lock on constraint's rel until end of xact */
491489
heap_close(rel, NoLock);
492490
}
493-
/* Lock the domain row in pg_type */
494491
else if (OidIsValid(con->contypid))
495492
{
496-
Relation typRel;
497-
HeapTuple typTup;
498-
ScanKeyData typKey[1];
499-
SysScanDesc typScan;
500-
int nkeys = 0;
501-
502-
typRel = heap_openr(TypeRelationName, RowExclusiveLock);
503-
504-
ScanKeyEntryInitialize(&typKey[nkeys++], 0x0,
505-
ObjectIdAttributeNumber, F_OIDEQ,
506-
ObjectIdGetDatum(con->contypid));
507-
508-
typScan = systable_beginscan(typRel, TypeOidIndex, true,
509-
SnapshotNow, nkeys, typKey);
510-
511-
typTup = systable_getnext(typScan);
512-
513-
if (!HeapTupleIsValid(typTup))
514-
elog(ERROR, "RemoveConstraintById: Type %d does not exist",
515-
con->contypid);
516-
517-
systable_endscan(typScan);
518-
519-
/* Keep lock on domain type until end of xact */
520-
heap_close(typRel, NoLock);
493+
/*
494+
* XXX for now, do nothing special when dropping a domain constraint
495+
*
496+
* Probably there should be some form of locking on the domain type,
497+
* but we have no such concept at the moment.
498+
*/
521499
}
522500
else
523501
{

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.58 2002/12/12 15:49:24 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.59 2002/12/12 20:35:12 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2737,7 +2737,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
27372737
/*
27382738
* Convert the A_EXPR in raw_expr into an EXPR
27392739
*/
2740-
expr = transformExpr(pstate, constr->raw_expr, NULL);
2740+
expr = transformExpr(pstate, constr->raw_expr);
27412741

27422742
/*
27432743
* Make sure it yields a boolean result.

0 commit comments

Comments
 (0)