Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb833c3d

Browse files
committed
Fix pg_get_constraintdef() to ensure CHECK constraints are always shown
with required outer parentheses. Breakage seems to be leftover fromdomain-constraint patches. This could be smarter about suppressingextra parens, but at this stage of the release cycle I want certaintynot cuteness.
1 parentec1fbbb commitb833c3d

File tree

3 files changed

+23
-64
lines changed

3 files changed

+23
-64
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*back to source text
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.156 2003/10/0222:24:54 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.157 2003/10/04 18:22:59 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -1048,23 +1048,11 @@ pg_get_constraintdef_worker(Oid constraintId, int prettyFlags)
10481048
Node*expr;
10491049
List*context;
10501050

1051-
/* Start off the constraint definition */
1052-
1053-
/*
1054-
* The consrc for CHECK constraints always seems to be
1055-
* bracketed, so we don't add extra brackets here.
1056-
*/
1057-
appendStringInfo(&buf,"CHECK ");
1058-
1059-
/* If we're pretty-printing we need to add brackets */
1060-
if (prettyFlags!=0)
1061-
appendStringInfo(&buf,"(");
1062-
1063-
/* Fetch constraint source */
1051+
/* Fetch constraint expression in parsetree form */
10641052
val=heap_getattr(tup,Anum_pg_constraint_conbin,
10651053
RelationGetDescr(conDesc),&isnull);
10661054
if (isnull)
1067-
elog(ERROR,"nullconsrc for constraint %u",
1055+
elog(ERROR,"nullconbin for constraint %u",
10681056
constraintId);
10691057

10701058
conbin=DatumGetCString(DirectFunctionCall1(textout,val));
@@ -1078,29 +1066,32 @@ pg_get_constraintdef_worker(Oid constraintId, int prettyFlags)
10781066
if (expr&&IsA(expr,List))
10791067
expr= (Node*)make_ands_explicit((List*)expr);
10801068

1069+
/* Set up deparsing context for Var nodes in constraint */
10811070
if (conForm->conrelid!=InvalidOid)
1082-
/* It's a Relation */
1071+
{
1072+
/* relation constraint */
10831073
context=deparse_context_for(get_rel_name(conForm->conrelid),
10841074
conForm->conrelid);
1075+
}
10851076
else
1086-
1087-
/*
1088-
* Since VARNOs aren't allowed in domain constraints,
1089-
* relation context isn't required as anything other
1090-
* than a shell.
1091-
*/
1092-
context=deparse_context_for(get_typname(conForm->contypid),
1093-
InvalidOid);
1077+
{
1078+
/* domain constraint --- can't have Vars */
1079+
context=NIL;
1080+
}
10941081

10951082
consrc=deparse_expression_pretty(expr,context, false, false,
10961083
prettyFlags,0);
10971084

1098-
/* Append the constraint source */
1099-
appendStringInfoString(&buf,consrc);
1100-
1101-
/* If we're pretty-printing we need to add brackets */
1102-
if (prettyFlags!=0)
1103-
appendStringInfo(&buf,")");
1085+
/*
1086+
* Now emit the constraint definition. There are cases where
1087+
* the constraint expression will be fully parenthesized and
1088+
* we don't need the outer parens ... but there are other
1089+
* cases where we do need 'em. Be conservative for now.
1090+
*
1091+
* Note that simply checking for leading '(' and trailing ')'
1092+
* would NOT be good enough, consider "(x > 0) AND (y > 0)".
1093+
*/
1094+
appendStringInfo(&buf,"CHECK (%s)",consrc);
11041095

11051096
break;
11061097
}

‎src/backend/utils/cache/lsyscache.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.107 2003/08/17 19:58:06 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.108 2003/10/04 18:22:59 tgl Exp $
1111
*
1212
* NOTES
1313
* Eventually, the index information should go through here, too.
@@ -1469,37 +1469,6 @@ get_typtype(Oid typid)
14691469
return'\0';
14701470
}
14711471

1472-
/*
1473-
* get_typname
1474-
*Returns the name of a given type.
1475-
*
1476-
* Returns a palloc'd copy of the string, or NULL if no such type.
1477-
*
1478-
* NOTE: since type name is not unique, be wary of code that uses this
1479-
* for anything except preparing error messages.
1480-
*/
1481-
char*
1482-
get_typname(Oidtypid)
1483-
{
1484-
HeapTupletp;
1485-
1486-
tp=SearchSysCache(TYPEOID,
1487-
ObjectIdGetDatum(typid),
1488-
0,0,0);
1489-
if (HeapTupleIsValid(tp))
1490-
{
1491-
Form_pg_typetyptup= (Form_pg_type)GETSTRUCT(tp);
1492-
char*result;
1493-
1494-
result=pstrdup(NameStr(typtup->typname));
1495-
ReleaseSysCache(tp);
1496-
returnresult;
1497-
}
1498-
else
1499-
returnNULL;
1500-
}
1501-
1502-
15031472
/*
15041473
* get_typ_typrelid
15051474
*

‎src/include/utils/lsyscache.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: lsyscache.h,v 1.81 2003/08/17 19:58:06 tgl Exp $
9+
* $Id: lsyscache.h,v 1.82 2003/10/04 18:22:59 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -83,7 +83,6 @@ extern char get_typtype(Oid typid);
8383
externOidget_typ_typrelid(Oidtypid);
8484
externOidget_element_type(Oidtypid);
8585
externOidget_array_type(Oidtypid);
86-
externchar*get_typname(Oidrelid);
8786
externvoidgetTypeInputInfo(Oidtype,Oid*typInput,Oid*typElem);
8887
externvoidgetTypeOutputInfo(Oidtype,Oid*typOutput,Oid*typElem,
8988
bool*typIsVarlena);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp