diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-04-08 23:20:04 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-04-08 23:20:04 +0000 |
commit | 730840c9b649a48604083270d48792915ca89233 (patch) | |
tree | cf3ccc25e61cdfc07061ebec63393d77b3a2f643 /src/backend/utils/adt/ruleutils.c | |
parent | 6fb5115850be766c42177cebf672c68c7d8e3ddd (diff) | |
download | postgresql-730840c9b649a48604083270d48792915ca89233.tar.gz postgresql-730840c9b649a48604083270d48792915ca89233.zip |
First phase of work on array improvements. ARRAY[x,y,z] constructor
expressions, ARRAY(sub-SELECT) expressions, some array functions.
Polymorphic functions using ANYARRAY/ANYELEMENT argument and return
types. Some regression tests in place, documentation is lacking.
Joe Conway, with some kibitzing from Tom Lane.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 9b34544a387..31135ff97fb 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.137 2003/03/20 18:58:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.138 2003/04/08 23:20:02 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -2217,6 +2217,7 @@ get_rule_expr(Node *node, deparse_context *context, { ArrayRef *aref = (ArrayRef *) node; bool savevarprefix = context->varprefix; + bool need_parens; List *lowlist; List *uplist; @@ -2229,7 +2230,16 @@ get_rule_expr(Node *node, deparse_context *context, */ if (aref->refassgnexpr) context->varprefix = false; + /* + * Parenthesize the argument unless it's a simple Var. + */ + need_parens = (aref->refassgnexpr == NULL) && + !IsA(aref->refexpr, Var); + if (need_parens) + appendStringInfoChar(buf, '('); get_rule_expr((Node *) aref->refexpr, context, showimplicit); + if (need_parens) + appendStringInfoChar(buf, ')'); context->varprefix = savevarprefix; lowlist = aref->reflowerindexpr; foreach(uplist, aref->refupperindexpr) @@ -2421,6 +2431,26 @@ get_rule_expr(Node *node, deparse_context *context, } break; + case T_ArrayExpr: + { + ArrayExpr *arrayexpr = (ArrayExpr *) node; + List *element; + char *sep; + + appendStringInfo(buf, "ARRAY["); + sep = ""; + foreach(element, arrayexpr->elements) + { + Node *e = (Node *) lfirst(element); + + appendStringInfo(buf, sep); + get_rule_expr(e, context, true); + sep = ", "; + } + appendStringInfo(buf, "]"); + } + break; + case T_CoalesceExpr: { CoalesceExpr *coalesceexpr = (CoalesceExpr *) node; @@ -2906,7 +2936,10 @@ get_sublink_expr(SubLink *sublink, deparse_context *context) char *sep; bool need_paren; - appendStringInfoChar(buf, '('); + if (sublink->subLinkType == ARRAY_SUBLINK) + appendStringInfo(buf, "ARRAY("); + else + appendStringInfoChar(buf, '('); if (sublink->lefthand != NIL) { @@ -2967,6 +3000,7 @@ get_sublink_expr(SubLink *sublink, deparse_context *context) break; case EXPR_SUBLINK: + case ARRAY_SUBLINK: need_paren = false; break; |