Skip to content

Commit 12437c5

Browse files
author
hackorum
committed
Apply findTargetlistEntrySQL92-COLLATE-1.patch
1 parent b597835 commit 12437c5

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/backend/parser/parse_clause.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,29 @@ findTargetlistEntrySQL92(ParseState *pstate, Node *node, List **tlist,
23262326
ParseExprKindName(exprKind), target_pos),
23272327
parser_errposition(pstate, aconst->location)));
23282328
}
2329+
/*
2330+
* If we've got a COLLATE clause covering up an integer referencing a
2331+
* targetlist expression, fix it up by replacing the integer with the
2332+
* referenced targetlist expression and let findTargetlistEntrySQL99
2333+
* finish it up by performing the remaining processing.
2334+
*/
2335+
if (IsA(node, CollateClause) &&
2336+
IsA(((CollateClause *) node)->arg, A_Const))
2337+
{
2338+
CollateClause *collclause = (CollateClause *) node;
2339+
TargetEntry *tle;
2340+
2341+
/* Recursively get the targetlist entry referenced by the integer. */
2342+
tle = findTargetlistEntrySQL92(pstate, collclause->arg, tlist,
2343+
exprKind);
2344+
2345+
/*
2346+
* Found one; replace the integer by the targetlist expression.
2347+
* findTargetlistEntrySQL99 will finish up the rest.
2348+
*/
2349+
Assert(tle != NULL);
2350+
collclause->arg = tle->expr;
2351+
}
23292352

23302353
/*
23312354
* Otherwise, we have an expression, so process it per SQL99 rules.

0 commit comments

Comments
 (0)