1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Determine the set of constraints applied to a domain at executor

startup, not in the parser; this allows ALTER DOMAIN to work correctly
with domain constraint operations stored in rules.  Rod Taylor;
code review by Tom Lane.
This commit is contained in:
Tom Lane
2003-02-03 21:15:45 +00:00
parent 464598b637
commit 3752e85bad
24 changed files with 524 additions and 339 deletions

View File

@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.133 2003/02/03 15:17:24 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.134 2003/02/03 21:15:44 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -638,11 +638,11 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
}
appendStringInfo(&buf, "%s", string);
/* Add ON UPDATE and ON DELETE clauses */
/* Add ON UPDATE and ON DELETE clauses, if needed */
switch (conForm->confupdtype)
{
case FKCONSTR_ACTION_NOACTION:
string = "";
string = NULL; /* suppress default */
break;
case FKCONSTR_ACTION_RESTRICT:
string = "RESTRICT";
@@ -659,16 +659,16 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
default:
elog(ERROR, "pg_get_constraintdef: Unknown confupdtype '%c' for constraint %u",
conForm->confupdtype, constraintId);
string = ""; /* keep compiler quiet */
string = NULL; /* keep compiler quiet */
break;
}
if (strlen(string) != 0)
if (string)
appendStringInfo(&buf, " ON UPDATE %s", string);
switch (conForm->confdeltype)
{
case FKCONSTR_ACTION_NOACTION:
string = "";
string = NULL; /* suppress default */
break;
case FKCONSTR_ACTION_RESTRICT:
string = "RESTRICT";
@@ -685,10 +685,10 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
default:
elog(ERROR, "pg_get_constraintdef: Unknown confdeltype '%c' for constraint %u",
conForm->confdeltype, constraintId);
string = ""; /* keep compiler quiet */
string = NULL; /* keep compiler quiet */
break;
}
if (strlen(string) != 0)
if (string)
appendStringInfo(&buf, " ON DELETE %s", string);
if (conForm->condeferrable)
@@ -2252,19 +2252,34 @@ get_rule_expr(Node *node, deparse_context *context,
}
break;
case T_ConstraintTest:
case T_CoerceToDomain:
{
ConstraintTest *ctest = (ConstraintTest *) node;
CoerceToDomain *ctest = (CoerceToDomain *) node;
Node *arg = (Node *) ctest->arg;
/*
* We assume that the operations of the constraint node
* need not be explicitly represented in the output.
* Any implicit coercion at the top level of the argument
* is presumably due to the domain's own internal typmod
* coercion, so do not force it to be shown.
*/
get_rule_expr((Node *) ctest->arg, context, showimplicit);
if (ctest->coercionformat == COERCE_IMPLICIT_CAST &&
!showimplicit)
{
/* don't show the implicit cast */
get_rule_expr(arg, context, false);
}
else
{
appendStringInfoChar(buf, '(');
get_rule_expr(arg, context, false);
appendStringInfo(buf, ")::%s",
format_type_with_typemod(ctest->resulttype,
ctest->resulttypmod));
}
}
break;
case T_ConstraintTestValue:
case T_CoerceToDomainValue:
appendStringInfo(buf, "VALUE");
break;
@@ -2444,7 +2459,8 @@ get_agg_expr(Aggref *aggref, deparse_context *context)
* the expression tree has a length-coercion node atop a type-coercion node.
*
* Note: avoid stripping a length-coercion node, since two successive
* coercions to different lengths aren't a no-op.
* coercions to different lengths aren't a no-op. Also, never strip a
* CoerceToDomain node, even though it might be effectively just RelabelType.
*/
static Node *
strip_type_coercion(Node *expr, Oid resultType)

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.89 2003/01/15 19:35:44 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.90 2003/02/03 21:15:44 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
@@ -1012,6 +1012,33 @@ get_typstorage(Oid typid)
return 'p';
}
/*
* get_typtypmod
*
* Given the type OID, return the typtypmod field (domain's typmod
* for base type)
*/
int32
get_typtypmod(Oid typid)
{
HeapTuple tp;
tp = SearchSysCache(TYPEOID,
ObjectIdGetDatum(typid),
0, 0, 0);
if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
int32 result;
result = typtup->typtypmod;
ReleaseSysCache(tp);
return result;
}
else
return -1;
}
/*
* get_typdefault
* Given a type OID, return the type's default value, if any.