mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Improve castNode notation by introducing list-extraction-specific variants.
This extends the castNode() notation introduced by commit 5bcab1114
to
provide, in one step, extraction of a list cell's pointer and coercion to
a concrete node type. For example, "lfirst_node(Foo, lc)" is the same
as "castNode(Foo, lfirst(lc))". Almost half of the uses of castNode
that have appeared so far include a list extraction call, so this is
pretty widely useful, and it saves a few more keystrokes compared to the
old way.
As with the previous patch, back-patch the addition of these macros to
pg_list.h, so that the notation will be available when back-patching.
Patch by me, after an idea of Andrew Gierth's.
Discussion: https://postgr.es/m/14197.1491841216@sss.pgh.pa.us
This commit is contained in:
@ -111,7 +111,7 @@ exprType(const Node *expr)
|
||||
|
||||
if (!qtree || !IsA(qtree, Query))
|
||||
elog(ERROR, "cannot get type for untransformed sublink");
|
||||
tent = castNode(TargetEntry, linitial(qtree->targetList));
|
||||
tent = linitial_node(TargetEntry, qtree->targetList);
|
||||
Assert(!tent->resjunk);
|
||||
type = exprType((Node *) tent->expr);
|
||||
if (sublink->subLinkType == ARRAY_SUBLINK)
|
||||
@ -324,7 +324,7 @@ exprTypmod(const Node *expr)
|
||||
|
||||
if (!qtree || !IsA(qtree, Query))
|
||||
elog(ERROR, "cannot get type for untransformed sublink");
|
||||
tent = castNode(TargetEntry, linitial(qtree->targetList));
|
||||
tent = linitial_node(TargetEntry, qtree->targetList);
|
||||
Assert(!tent->resjunk);
|
||||
return exprTypmod((Node *) tent->expr);
|
||||
/* note we don't need to care if it's an array */
|
||||
@ -382,7 +382,7 @@ exprTypmod(const Node *expr)
|
||||
return -1; /* no point in trying harder */
|
||||
foreach(arg, cexpr->args)
|
||||
{
|
||||
CaseWhen *w = castNode(CaseWhen, lfirst(arg));
|
||||
CaseWhen *w = lfirst_node(CaseWhen, arg);
|
||||
|
||||
if (exprType((Node *) w->result) != casetype)
|
||||
return -1;
|
||||
@ -809,7 +809,7 @@ exprCollation(const Node *expr)
|
||||
|
||||
if (!qtree || !IsA(qtree, Query))
|
||||
elog(ERROR, "cannot get collation for untransformed sublink");
|
||||
tent = castNode(TargetEntry, linitial(qtree->targetList));
|
||||
tent = linitial_node(TargetEntry, qtree->targetList);
|
||||
Assert(!tent->resjunk);
|
||||
coll = exprCollation((Node *) tent->expr);
|
||||
/* collation doesn't change if it's converted to array */
|
||||
@ -1054,7 +1054,7 @@ exprSetCollation(Node *expr, Oid collation)
|
||||
|
||||
if (!qtree || !IsA(qtree, Query))
|
||||
elog(ERROR, "cannot set collation for untransformed sublink");
|
||||
tent = castNode(TargetEntry, linitial(qtree->targetList));
|
||||
tent = linitial_node(TargetEntry, qtree->targetList);
|
||||
Assert(!tent->resjunk);
|
||||
Assert(collation == exprCollation((Node *) tent->expr));
|
||||
}
|
||||
@ -2058,7 +2058,7 @@ expression_tree_walker(Node *node,
|
||||
/* we assume walker doesn't care about CaseWhens, either */
|
||||
foreach(temp, caseexpr->args)
|
||||
{
|
||||
CaseWhen *when = castNode(CaseWhen, lfirst(temp));
|
||||
CaseWhen *when = lfirst_node(CaseWhen, temp);
|
||||
|
||||
if (walker(when->expr, context))
|
||||
return true;
|
||||
@ -3308,7 +3308,7 @@ raw_expression_tree_walker(Node *node,
|
||||
/* we assume walker doesn't care about CaseWhens, either */
|
||||
foreach(temp, caseexpr->args)
|
||||
{
|
||||
CaseWhen *when = castNode(CaseWhen, lfirst(temp));
|
||||
CaseWhen *when = lfirst_node(CaseWhen, temp);
|
||||
|
||||
if (walker(when->expr, context))
|
||||
return true;
|
||||
@ -3807,7 +3807,7 @@ planstate_walk_subplans(List *plans,
|
||||
|
||||
foreach(lc, plans)
|
||||
{
|
||||
SubPlanState *sps = castNode(SubPlanState, lfirst(lc));
|
||||
SubPlanState *sps = lfirst_node(SubPlanState, lc);
|
||||
|
||||
if (walker(sps->planstate, context))
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user