summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorTom Lane2011-03-11 21:27:51 +0000
committerTom Lane2011-03-11 21:28:18 +0000
commit8acdb8bf9cebc42cee5aa96a2d594756b44173c9 (patch)
tree3db28ae99dfb962e4ac5f2f338a15d2b5c7a476e /src/backend/parser
parent7a8f43968add3c69b79c49ef236d945e643dcb1e (diff)
Split CollateClause into separate raw and analyzed node types.
CollateClause is now used only in raw grammar output, and CollateExpr after parse analysis. This is for clarity and to avoid carrying collation names in post-analysis parse trees: that's both wasteful and possibly misleading, since the collation's name could be changed while the parsetree still exists. Also, clean up assorted infelicities and omissions in processing of the node type.
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y10
-rw-r--r--src/backend/parser/parse_coerce.c16
-rw-r--r--src/backend/parser/parse_expr.c10
-rw-r--r--src/backend/parser/parse_target.c2
-rw-r--r--src/backend/parser/parse_type.c2
-rw-r--r--src/backend/parser/parse_utilcmd.c2
6 files changed, 23 insertions, 19 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 373d2adc71c..1633499f939 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -1993,8 +1993,7 @@ opt_collate_clause:
{
CollateClause *n = makeNode(CollateClause);
n->arg = NULL;
- n->collnames = $2;
- n->collOid = InvalidOid;
+ n->collname = $2;
n->location = @1;
$$ = (Node *) n;
}
@@ -2537,8 +2536,7 @@ ColConstraint:
*/
CollateClause *n = makeNode(CollateClause);
n->arg = NULL;
- n->collnames = $2;
- n->collOid = InvalidOid;
+ n->collname = $2;
n->location = @1;
$$ = (Node *) n;
}
@@ -9690,8 +9688,8 @@ a_expr: c_expr { $$ = $1; }
| a_expr COLLATE any_name
{
CollateClause *n = makeNode(CollateClause);
- n->arg = (Expr *) $1;
- n->collnames = $3;
+ n->arg = $1;
+ n->collname = $3;
n->location = @2;
$$ = (Node *) n;
}
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 2fd808d26b2..6aff34dd90d 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -279,11 +279,17 @@ coerce_type(ParseState *pstate, Node *node,
if (result)
return result;
}
- if (IsA(node, CollateClause))
+ if (IsA(node, CollateExpr))
{
- CollateClause *cc = (CollateClause *) node;
+ /*
+ * XXX very ugly kluge to push the coercion underneath the CollateExpr.
+ * This needs to be rethought, as it almost certainly doesn't cover
+ * all cases.
+ */
+ CollateExpr *cc = (CollateExpr *) node;
- cc->arg = (Expr *) coerce_type(pstate, (Node *) cc->arg, inputTypeId, targetTypeId, targetTypeMod,
+ cc->arg = (Expr *) coerce_type(pstate, (Node *) cc->arg,
+ inputTypeId, targetTypeId, targetTypeMod,
ccontext, cformat, location);
return (Node *) cc;
}
@@ -2121,7 +2127,7 @@ select_common_collation(ParseState *pstate, List *exprs, bool none_ok)
{
Node *pexpr = (Node *) lfirst(lc);
Oid pcoll = exprCollation(pexpr);
- bool pexplicit = IsA(pexpr, CollateClause);
+ bool pexplicit = IsA(pexpr, CollateExpr);
if (pcoll && pexplicit)
{
@@ -2130,7 +2136,7 @@ select_common_collation(ParseState *pstate, List *exprs, bool none_ok)
{
Node *nexpr = (Node *) lfirst(lc2);
Oid ncoll = exprCollation(nexpr);
- bool nexplicit = IsA(nexpr, CollateClause);
+ bool nexplicit = IsA(nexpr, CollateExpr);
if (!ncoll || !nexplicit)
continue;
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 7a4f8cc2497..17bd2bf50ae 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -318,6 +318,7 @@ transformExpr(ParseState *pstate, Node *expr)
case T_CoerceViaIO:
case T_ArrayCoerceExpr:
case T_ConvertRowtypeExpr:
+ case T_CollateExpr:
case T_CaseTestExpr:
case T_ArrayExpr:
case T_CoerceToDomain:
@@ -2103,11 +2104,11 @@ transformTypeCast(ParseState *pstate, TypeCast *tc)
static Node *
transformCollateClause(ParseState *pstate, CollateClause *c)
{
- CollateClause *newc;
+ CollateExpr *newc;
Oid argtype;
- newc = makeNode(CollateClause);
- newc->arg = (Expr *) transformExpr(pstate, (Node *) c->arg);
+ newc = makeNode(CollateExpr);
+ newc->arg = (Expr *) transformExpr(pstate, c->arg);
argtype = exprType((Node *) newc->arg);
/*
@@ -2121,8 +2122,7 @@ transformCollateClause(ParseState *pstate, CollateClause *c)
format_type_be(argtype)),
parser_errposition(pstate, c->location)));
- newc->collOid = LookupCollation(pstate, c->collnames, c->location);
- newc->collnames = c->collnames;
+ newc->collOid = LookupCollation(pstate, c->collname, c->location);
newc->location = c->location;
return (Node *) newc;
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index c0eaea71a66..fd1529fb3f9 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1583,7 +1583,7 @@ FigureColnameInternal(Node *node, char **name)
}
break;
case T_CollateClause:
- return FigureColnameInternal((Node *) ((CollateClause *) node)->arg, name);
+ return FigureColnameInternal(((CollateClause *) node)->arg, name);
case T_CaseExpr:
strength = FigureColnameInternal((Node *) ((CaseExpr *) node)->defresult,
name);
diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c
index 2ba9bf51816..f413593f602 100644
--- a/src/backend/parser/parse_type.c
+++ b/src/backend/parser/parse_type.c
@@ -471,7 +471,7 @@ GetColumnDefCollation(ParseState *pstate, ColumnDef *coldef, Oid typeOid)
{
/* We have a raw COLLATE clause, so look up the collation */
location = coldef->collClause->location;
- result = LookupCollation(pstate, coldef->collClause->collnames,
+ result = LookupCollation(pstate, coldef->collClause->collname,
location);
}
else if (OidIsValid(coldef->collOid))
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index e876853af02..06baf89886a 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -2467,7 +2467,7 @@ transformColumnType(CreateStmtContext *cxt, ColumnDef *column)
Oid collOid;
collOid = LookupCollation(cxt->pstate,
- column->collClause->collnames,
+ column->collClause->collname,
column->collClause->location);
/* Complain if COLLATE is applied to an uncollatable type */
if (!OidIsValid(typtup->typcollation))