mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
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.
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
Reference in New Issue
Block a user