if (defel->arg && IsA(defel->arg, A_Star))
cstate->force_quote_all = true;
else if (defel->arg && IsA(defel->arg, List))
- cstate->force_quote = (List *) defel->arg;
+ cstate->force_quote = castNode(List, defel->arg);
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot get type for untransformed sublink");
- tent = (TargetEntry *) linitial(qtree->targetList);
- Assert(IsA(tent, TargetEntry));
+ tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
type = exprType((Node *) tent->expr);
if (sublink->subLinkType == ARRAY_SUBLINK)
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot get type for untransformed sublink");
- tent = (TargetEntry *) linitial(qtree->targetList);
- Assert(IsA(tent, TargetEntry));
+ tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
return exprTypmod((Node *) tent->expr);
/* note we don't need to care if it's an array */
return -1; /* no point in trying harder */
foreach(arg, cexpr->args)
{
- CaseWhen *w = (CaseWhen *) lfirst(arg);
+ CaseWhen *w = castNode(CaseWhen, lfirst(arg));
- Assert(IsA(w, CaseWhen));
if (exprType((Node *) w->result) != casetype)
return -1;
if (exprTypmod((Node *) w->result) != typmod)
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot get collation for untransformed sublink");
- tent = (TargetEntry *) linitial(qtree->targetList);
- Assert(IsA(tent, TargetEntry));
+ tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
coll = exprCollation((Node *) tent->expr);
/* collation doesn't change if it's converted to array */
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot set collation for untransformed sublink");
- tent = (TargetEntry *) linitial(qtree->targetList);
- Assert(IsA(tent, TargetEntry));
+ tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
Assert(collation == exprCollation((Node *) tent->expr));
}
/* we assume walker doesn't care about CaseWhens, either */
foreach(temp, caseexpr->args)
{
- CaseWhen *when = (CaseWhen *) lfirst(temp);
+ CaseWhen *when = castNode(CaseWhen, lfirst(temp));
- Assert(IsA(when, CaseWhen));
if (walker(when->expr, context))
return true;
if (walker(when->result, context))
/* we assume walker doesn't care about CaseWhens, either */
foreach(temp, caseexpr->args)
{
- CaseWhen *when = (CaseWhen *) lfirst(temp);
+ CaseWhen *when = castNode(CaseWhen, lfirst(temp));
- Assert(IsA(when, CaseWhen));
if (walker(when->expr, context))
return true;
if (walker(when->result, context))
foreach(lc, plans)
{
- SubPlanState *sps = (SubPlanState *) lfirst(lc);
+ SubPlanState *sps = castNode(SubPlanState, lfirst(lc));
- Assert(IsA(sps, SubPlanState));
if (walker(sps->planstate, context))
return true;
}
if (subquery->setOperations != NULL)
return false;
/* Check whether setop component output types match top level */
- topop = (SetOperationStmt *) topquery->setOperations;
- Assert(topop && IsA(topop, SetOperationStmt));
+ topop = castNode(SetOperationStmt, topquery->setOperations);
+ Assert(topop);
compare_tlist_datatypes(subquery->targetList,
topop->colTypes,
safetyInfo);
foreach(lc, qual_clauses)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
- Assert(IsA(rinfo, RestrictInfo));
if (rinfo->pseudoconstant)
continue; /* we may drop pseudoconstants here */
if (list_member_ptr(indexquals, rinfo))
*/
foreach(lc, windowFuncs)
{
- WindowFunc *wfunc = (WindowFunc *) lfirst(lc);
+ WindowFunc *wfunc = castNode(WindowFunc, lfirst(lc));
Cost wfunccost;
QualCost argcosts;
- Assert(IsA(wfunc, WindowFunc));
-
wfunccost = get_func_cost(wfunc->winfnoid) * cpu_operator_cost;
/* also add the input expressions' cost to per-input-row costs */
innerbucketsize = 1.0;
foreach(hcl, hashclauses)
{
- RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(hcl);
+ RestrictInfo *restrictinfo = castNode(RestrictInfo, lfirst(hcl));
Selectivity thisbucketsize;
- Assert(IsA(restrictinfo, RestrictInfo));
-
/*
* First we have to figure out which side of the hashjoin clause
* is the inner side.
joinquals = NIL;
foreach(l, restrictlist)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
- Assert(IsA(rinfo, RestrictInfo));
if (!rinfo->is_pushed_down)
joinquals = lappend(joinquals, rinfo);
}
/* Grovel through the clauses to separate into two lists */
foreach(l, restrictlist)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
- Assert(IsA(rinfo, RestrictInfo));
if (rinfo->is_pushed_down)
pushedquals = lappend(pushedquals, rinfo);
else
*/
foreach(lc, subroot->parse->targetList)
{
- TargetEntry *te = (TargetEntry *) lfirst(lc);
+ TargetEntry *te = castNode(TargetEntry, lfirst(lc));
Node *texpr = (Node *) te->expr;
int32 item_width = 0;
- Assert(IsA(te, TargetEntry));
/* junk columns aren't visible to upper query */
if (te->resjunk)
continue;
foreach(lc, clauses)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
List *pathlist;
Path *bitmapqual;
ListCell *j;
- Assert(IsA(rinfo, RestrictInfo));
/* Ignore RestrictInfos that aren't ORs */
if (!restriction_is_or_clause(rinfo))
continue;
}
else
{
+ RestrictInfo *rinfo = castNode(RestrictInfo, orarg);
List *orargs;
- Assert(IsA(orarg, RestrictInfo));
- Assert(!restriction_is_or_clause((RestrictInfo *) orarg));
+ Assert(!restriction_is_or_clause(rinfo));
orargs = list_make1(orarg);
indlist = build_paths_for_OR(root, rel,
foreach(lc, clauses)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
- Assert(IsA(rinfo, RestrictInfo));
match_clause_to_index(index, rinfo, clauseset);
}
}
*/
foreach(lc, restrictlist)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
- Assert(IsA(rinfo, RestrictInfo));
if (only_pushed_down && !rinfo->is_pushed_down)
continue;
*/
foreach(l, clause_list)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Oid op;
Var *var;
* caller's mergejoinability test should have selected only
* OpExprs.
*/
- Assert(IsA(rinfo->clause, OpExpr));
- op = ((OpExpr *) rinfo->clause)->opno;
+ op = castNode(OpExpr, rinfo->clause)->opno;
/* caller identified the inner side for us */
if (rinfo->outer_is_left)
*/
if (query->setOperations)
{
- SetOperationStmt *topop = (SetOperationStmt *) query->setOperations;
+ SetOperationStmt *topop = castNode(SetOperationStmt, query->setOperations);
- Assert(IsA(topop, SetOperationStmt));
Assert(topop->op != SETOP_NONE);
if (!topop->all)
{
case T_IndexScan:
case T_IndexOnlyScan:
- Assert(IsA(best_path, IndexPath));
- scan_clauses = ((IndexPath *) best_path)->indexinfo->indrestrictinfo;
+ scan_clauses = castNode(IndexPath, best_path)->indexinfo->indrestrictinfo;
break;
default:
scan_clauses = rel->baserestrictinfo;
qpqual = NIL;
foreach(l, scan_clauses)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
- Assert(IsA(rinfo, RestrictInfo));
if (rinfo->pseudoconstant)
continue; /* we may drop pseudoconstants here */
if (list_member_ptr(indexquals, rinfo))
qpqual = NIL;
foreach(l, scan_clauses)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Node *clause = (Node *) rinfo->clause;
- Assert(IsA(rinfo, RestrictInfo));
if (rinfo->pseudoconstant)
continue; /* we may drop pseudoconstants here */
if (list_member(indexquals, clause))
ListCell *l;
/* Use the regular indexscan plan build machinery... */
- iscan = (IndexScan *) create_indexscan_plan(root, ipath,
- NIL, NIL, false);
- Assert(IsA(iscan, IndexScan));
+ iscan = castNode(IndexScan,
+ create_indexscan_plan(root, ipath,
+ NIL, NIL, false));
/* then convert to a bitmap indexscan */
plan = (Plan *) make_bitmap_indexscan(iscan->scan.scanrelid,
iscan->indexid,
* Invoke custom plan provider to create the Plan node represented by the
* CustomPath.
*/
- cplan = (CustomScan *) best_path->methods->PlanCustomPath(root,
- rel,
- best_path,
- tlist,
- scan_clauses,
- custom_plans);
- Assert(IsA(cplan, CustomScan));
+ cplan = castNode(CustomScan,
+ best_path->methods->PlanCustomPath(root,
+ rel,
+ best_path,
+ tlist,
+ scan_clauses,
+ custom_plans));
/*
* Copy cost data from Path to Plan; no need to make custom-plan providers
i = 0;
foreach(lc, best_path->path_mergeclauses)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
EquivalenceClass *oeclass;
EquivalenceClass *ieclass;
PathKey *opathkey;
ListCell *l2;
/* fetch outer/inner eclass from mergeclause */
- Assert(IsA(rinfo, RestrictInfo));
if (rinfo->outer_is_left)
{
oeclass = rinfo->left_ec;
forboth(lcc, index_path->indexquals, lci, index_path->indexqualcols)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lcc);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lcc));
int indexcol = lfirst_int(lci);
Node *clause;
- Assert(IsA(rinfo, RestrictInfo));
-
/*
* Replace any outer-relation variables with nestloop params.
*
window_target = copy_pathtarget(window_target);
foreach(lc2, wflists->windowFuncs[wc->winref])
{
- WindowFunc *wfunc = (WindowFunc *) lfirst(lc2);
+ WindowFunc *wfunc = castNode(WindowFunc, lfirst(lc2));
- Assert(IsA(wfunc, WindowFunc));
add_column_to_pathtarget(window_target, (Expr *) wfunc, 0);
window_target->width += get_typavgwidth(wfunc->wintype, -1);
}
*/
foreach(lc, root->rowMarks)
{
- PlanRowMark *rc = (PlanRowMark *) lfirst(lc);
+ PlanRowMark *rc = castNode(PlanRowMark, lfirst(lc));
PlanRowMark *newrc;
- Assert(IsA(rc, PlanRowMark));
-
/* flat copy is enough since all fields are scalars */
newrc = (PlanRowMark *) palloc(sizeof(PlanRowMark));
memcpy(newrc, rc, sizeof(PlanRowMark));
/* In cases such as EXISTS, tlist might be empty; arbitrarily use VOID */
if (plan->targetlist)
{
- TargetEntry *tent = (TargetEntry *) linitial(plan->targetlist);
+ TargetEntry *tent = castNode(TargetEntry, linitial(plan->targetlist));
- Assert(IsA(tent, TargetEntry));
if (!tent->resjunk)
{
*coltype = exprType((Node *) tent->expr);
AlternativeSubPlan *asplan;
/* OK, convert to SubPlan format. */
- hashplan = (SubPlan *) build_subplan(root, plan, subroot,
- plan_params,
- ANY_SUBLINK, 0,
- newtestexpr,
- false, true,
- best_path->parallel_safe);
+ hashplan = castNode(SubPlan,
+ build_subplan(root, plan, subroot,
+ plan_params,
+ ANY_SUBLINK, 0,
+ newtestexpr,
+ false, true,
+ best_path->parallel_safe));
/* Check we got what we expected */
- Assert(IsA(hashplan, SubPlan));
Assert(hashplan->parParam == NIL);
Assert(hashplan->useHashTable);
/* build_subplan won't have filled in paramIds */
elog(ERROR, "subquery is bogus");
/* Is it a set-operation query at all? */
- topop = (SetOperationStmt *) subquery->setOperations;
+ topop = castNode(SetOperationStmt, subquery->setOperations);
if (!topop)
return false;
- Assert(IsA(topop, SetOperationStmt));
/* Can't handle ORDER BY, LIMIT/OFFSET, locking, or WITH */
if (subquery->sortClause ||
RangeTblRef *rtr;
/* Shouldn't be called unless query has setops */
- topop = (SetOperationStmt *) parse->setOperations;
- Assert(topop && IsA(topop, SetOperationStmt));
+ topop = castNode(SetOperationStmt, parse->setOperations);
+ Assert(topop);
/* Can't optimize away a recursive UNION */
if (root->hasRecursion)
plan_set_operations(PlannerInfo *root)
{
Query *parse = root->parse;
- SetOperationStmt *topop = (SetOperationStmt *) parse->setOperations;
+ SetOperationStmt *topop = castNode(SetOperationStmt, parse->setOperations);
Node *node;
RangeTblEntry *leftmostRTE;
Query *leftmostQuery;
Path *path;
List *top_tlist;
- Assert(topop && IsA(topop, SetOperationStmt));
+ Assert(topop);
/* check for unsupported stuff */
Assert(parse->jointree->fromlist == NIL);
attno = InvalidAttrNumber;
foreach(lc, translated_vars)
{
- Var *var = (Var *) lfirst(lc);
+ Var *var = castNode(Var, lfirst(lc));
attno++;
if (var == NULL) /* ignore dropped columns */
continue;
- Assert(IsA(var, Var));
if (whole_row ||
bms_is_member(attno - FirstLowInvalidHeapAttributeNumber,
parent_privs))
* Since the underlying operator is "=", must negate
* its result
*/
- Const *csimple = (Const *) simple;
+ Const *csimple = castNode(Const, simple);
- Assert(IsA(csimple, Const));
csimple->constvalue =
BoolGetDatum(!DatumGetBool(csimple->constvalue));
return (Node *) csimple;
const_true_cond = false;
foreach(arg, caseexpr->args)
{
- CaseWhen *oldcasewhen = (CaseWhen *) lfirst(arg);
+ CaseWhen *oldcasewhen = castNode(CaseWhen, lfirst(arg));
Node *casecond;
Node *caseresult;
- Assert(IsA(oldcasewhen, CaseWhen));
-
/* Simplify this alternative's test condition */
casecond = eval_const_expressions_mutator((Node *) oldcasewhen->expr,
context);
if (isnull)
elog(ERROR, "not enough default arguments");
str = TextDatumGetCString(proargdefaults);
- defaults = (List *) stringToNode(str);
- Assert(IsA(defaults, List));
+ defaults = castNode(List, stringToNode(str));
pfree(str);
return defaults;
}
foreach(lc2, andargs)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc2);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc2));
- Assert(IsA(rinfo, RestrictInfo));
if (restriction_is_or_clause(rinfo))
{
/*
}
else
{
- Assert(IsA(orarg, RestrictInfo));
- Assert(!restriction_is_or_clause((RestrictInfo *) orarg));
- if (is_safe_restriction_clause_for((RestrictInfo *) orarg, rel))
- subclauses = lappend(subclauses,
- ((RestrictInfo *) orarg)->clause);
+ RestrictInfo *rinfo = castNode(RestrictInfo, orarg);
+
+ Assert(!restriction_is_or_clause(rinfo));
+ if (is_safe_restriction_clause_for(rinfo, rel))
+ subclauses = lappend(subclauses, rinfo->clause);
}
/*
foreach(l, restrictinfo_list)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
-
- Assert(IsA(rinfo, RestrictInfo));
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Assert(!rinfo->pseudoconstant);
foreach(l, restrictinfo_list)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
-
- Assert(IsA(rinfo, RestrictInfo));
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
if (rinfo->pseudoconstant == pseudoconstant)
result = lappend(result, rinfo->clause);
foreach(l, restrictinfo_list)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
-
- Assert(IsA(rinfo, RestrictInfo));
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
if (rinfo->is_pushed_down)
{
AttrNumber attr_num;
TargetEntry *tle;
- col = (ResTarget *) lfirst(icols);
- Assert(IsA(col, ResTarget));
+ col = castNode(ResTarget, lfirst(icols));
attr_num = (AttrNumber) lfirst_int(attnos);
tle = makeTargetEntry(expr,
Expr *expr = (Expr *) lfirst(lc);
ResTarget *col;
- col = (ResTarget *) lfirst(icols);
- Assert(IsA(col, ResTarget));
+ col = castNode(ResTarget, lfirst(icols));
expr = transformAssignedExpr(pstate, expr,
EXPR_KIND_INSERT_TARGET,
/*
* Recursively transform the components of the tree.
*/
- sostmt = (SetOperationStmt *) transformSetOperationTree(pstate, stmt,
- true,
- NULL);
- Assert(sostmt && IsA(sostmt, SetOperationStmt));
+ sostmt = castNode(SetOperationStmt,
+ transformSetOperationTree(pstate, stmt, true, NULL));
+ Assert(sostmt);
qry->setOperations = (Node *) sostmt;
/*
}
if (orig_tl == NULL)
elog(ERROR, "UPDATE target count mismatch --- internal error");
- origTarget = (ResTarget *) lfirst(orig_tl);
- Assert(IsA(origTarget, ResTarget));
+ origTarget = castNode(ResTarget, lfirst(orig_tl));
attrno = attnameAttNum(pstate->p_target_relation,
origTarget->name, true);
ColConstraint:
CONSTRAINT name ColConstraintElem
{
- Constraint *n = (Constraint *) $3;
- Assert(IsA(n, Constraint));
+ Constraint *n = castNode(Constraint, $3);
n->conname = $2;
n->location = @1;
$$ = (Node *) n;
TableConstraint:
CONSTRAINT name ConstraintElem
{
- Constraint *n = (Constraint *) $3;
- Assert(IsA(n, Constraint));
+ Constraint *n = castNode(Constraint, $3);
n->conname = $2;
n->location = @1;
$$ = (Node *) n;
}
| ARRAY array_expr
{
- A_ArrayExpr *n = (A_ArrayExpr *) $2;
- Assert(IsA(n, A_ArrayExpr));
+ A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
/* point outermost A_ArrayExpr to the ARRAY keyword */
n->location = @1;
$$ = (Node *)n;
rel = transformFromClauseItem(pstate, rts->relation,
top_rte, top_rti, namespace);
/* Currently, grammar could only return a RangeVar as contained rel */
- Assert(IsA(rel, RangeTblRef));
- rtr = (RangeTblRef *) rel;
+ rtr = castNode(RangeTblRef, rel);
rte = rt_fetch(rtr->rtindex, pstate->p_rtable);
/* We only support this on plain relations and matviews */
if (rte->relkind != RELKIND_RELATION &&
if (qtree->targetList == NIL)
return false;
- tent = (TargetEntry *) linitial(qtree->targetList);
- Assert(IsA(tent, TargetEntry));
+ tent = castNode(TargetEntry, linitial(qtree->targetList));
if (tent->resjunk)
return false;
foreach(lc, expr->args)
{
- CaseWhen *when = (CaseWhen *) lfirst(lc);
-
- Assert(IsA(when, CaseWhen));
+ CaseWhen *when = castNode(CaseWhen, lfirst(lc));
/*
* The condition expressions mustn't affect
/* Process aggregated args, holding resjunk ones at arm's length */
foreach(lc, aggref->args)
{
- TargetEntry *tle = (TargetEntry *) lfirst(lc);
+ TargetEntry *tle = castNode(TargetEntry, lfirst(lc));
- Assert(IsA(tle, TargetEntry));
if (tle->resjunk)
assign_expr_collations(loccontext->pstate, (Node *) tle);
else
/* Process aggregated args appropriately */
foreach(lc, aggref->args)
{
- TargetEntry *tle = (TargetEntry *) lfirst(lc);
+ TargetEntry *tle = castNode(TargetEntry, lfirst(lc));
- Assert(IsA(tle, TargetEntry));
if (merge_sort_collations)
(void) assign_collations_walker((Node *) tle, loccontext);
else
/* ROW() op ROW() is handled specially */
lexpr = transformExprRecurse(pstate, lexpr);
rexpr = transformExprRecurse(pstate, rexpr);
- Assert(IsA(lexpr, RowExpr));
- Assert(IsA(rexpr, RowExpr));
result = make_row_comparison_op(pstate,
a->name,
- ((RowExpr *) lexpr)->args,
- ((RowExpr *) rexpr)->args,
+ castNode(RowExpr, lexpr)->args,
+ castNode(RowExpr, rexpr)->args,
a->location);
}
else
/* Deconstruct A_Expr into three subexprs */
aexpr = a->lexpr;
- Assert(IsA(a->rexpr, List));
- args = (List *) a->rexpr;
+ args = castNode(List, a->rexpr);
Assert(list_length(args) == 2);
bexpr = (Node *) linitial(args);
cexpr = (Node *) lsecond(args);
resultexprs = NIL;
foreach(l, c->args)
{
- CaseWhen *w = (CaseWhen *) lfirst(l);
+ CaseWhen *w = castNode(CaseWhen, lfirst(l));
CaseWhen *neww = makeNode(CaseWhen);
Node *warg;
- Assert(IsA(w, CaseWhen));
-
warg = (Node *) w->expr;
if (placeholder)
{
foreach(lc, x->named_args)
{
- ResTarget *r = (ResTarget *) lfirst(lc);
+ ResTarget *r = castNode(ResTarget, lfirst(lc));
Node *expr;
char *argname;
- Assert(IsA(r, ResTarget));
-
expr = transformExprRecurse(pstate, r->val);
if (r->name)
Node *rarg = (Node *) lfirst(r);
OpExpr *cmp;
- cmp = (OpExpr *) make_op(pstate, opname, larg, rarg, location);
- Assert(IsA(cmp, OpExpr));
+ cmp = castNode(OpExpr, make_op(pstate, opname, larg, rarg, location));
/*
* We don't use coerce_to_boolean here because we insist on the
&isnull);
Assert(!isnull);
str = TextDatumGetCString(proargdefaults);
- defaults = (List *) stringToNode(str);
- Assert(IsA(defaults, List));
+ defaults = castNode(List, stringToNode(str));
pfree(str);
/* Delete any unused defaults from the returned list */
*/
foreach(idx, indirection)
{
- A_Indices *ai = (A_Indices *) lfirst(idx);
+ A_Indices *ai = castNode(A_Indices, lfirst(idx));
Node *subexpr;
- Assert(IsA(ai, A_Indices));
if (isSlice)
{
if (ai->lidx)
JoinExpr *j;
if (rtindex > 0 && rtindex <= list_length(pstate->p_joinexprs))
- j = (JoinExpr *) list_nth(pstate->p_joinexprs, rtindex - 1);
+ j = castNode(JoinExpr, list_nth(pstate->p_joinexprs, rtindex - 1));
else
j = NULL;
if (j == NULL)
elog(ERROR, "could not find JoinExpr for whole-row reference");
- Assert(IsA(j, JoinExpr));
/* Note: we can't see FromExpr here */
if (IsA(j->larg, RangeTblRef))
initStringInfo(&string);
foreach(l, typenames)
{
- TypeName *typeName = (TypeName *) lfirst(l);
+ TypeName *typeName = castNode(TypeName, lfirst(l));
- Assert(IsA(typeName, TypeName));
if (l != list_head(typenames))
appendStringInfoChar(&string, ',');
appendTypeNameToBuffer(typeName, &string);
foreach(clist, column->constraints)
{
- constraint = lfirst(clist);
- Assert(IsA(constraint, Constraint));
+ constraint = castNode(Constraint, lfirst(clist));
switch (constraint->contype)
{
*/
foreach(lc, cxt->ixconstraints)
{
- Constraint *constraint = (Constraint *) lfirst(lc);
+ Constraint *constraint = castNode(Constraint, lfirst(lc));
- Assert(IsA(constraint, Constraint));
Assert(constraint->contype == CONSTR_PRIMARY ||
constraint->contype == CONSTR_UNIQUE ||
constraint->contype == CONSTR_EXCLUSION);
List *opname;
Assert(list_length(pair) == 2);
- elem = (IndexElem *) linitial(pair);
- Assert(IsA(elem, IndexElem));
- opname = (List *) lsecond(pair);
- Assert(IsA(opname, List));
+ elem = castNode(IndexElem, linitial(pair));
+ opname = castNode(List, lsecond(pair));
index->indexParams = lappend(index->indexParams, elem);
index->excludeOpNames = lappend(index->excludeOpNames, opname);
foreach(columns, cxt->columns)
{
- column = (ColumnDef *) lfirst(columns);
- Assert(IsA(column, ColumnDef));
+ column = castNode(ColumnDef, lfirst(columns));
if (strcmp(column->colname, key) == 0)
{
found = true;
foreach(inher, cxt->inhRelations)
{
- RangeVar *inh = (RangeVar *) lfirst(inher);
+ RangeVar *inh = castNode(RangeVar, lfirst(inher));
Relation rel;
int count;
- Assert(IsA(inh, RangeVar));
rel = heap_openrv(inh, AccessShareLock);
/* check user requested inheritance from valid relkind */
if (rel->rd_rel->relkind != RELKIND_RELATION &&
case AT_AddColumn:
case AT_AddColumnToView:
{
- ColumnDef *def = (ColumnDef *) cmd->def;
+ ColumnDef *def = castNode(ColumnDef, cmd->def);
- Assert(IsA(def, ColumnDef));
transformColumnDefinition(&cxt, def);
/*
*/
foreach(l, cxt.alist)
{
- IndexStmt *idxstmt = (IndexStmt *) lfirst(l);
+ IndexStmt *idxstmt = castNode(IndexStmt, lfirst(l));
- Assert(IsA(idxstmt, IndexStmt));
idxstmt = transformIndexStmt(relid, idxstmt, queryString);
newcmd = makeNode(AlterTableCmd);
newcmd->subtype = OidIsValid(idxstmt->indexOid) ? AT_AddIndexConstraint : AT_AddIndex;
* there should be a single base relation.
*/
Assert(list_length(viewquery->jointree->fromlist) == 1);
- rtr = (RangeTblRef *) linitial(viewquery->jointree->fromlist);
- Assert(IsA(rtr, RangeTblRef));
+ rtr = castNode(RangeTblRef, linitial(viewquery->jointree->fromlist));
/* Initialize the optional return values */
if (updatable_cols != NULL)
if (tle->resjunk)
continue;
- var = (Var *) tle->expr;
- Assert(IsA(var, Var));
+ var = castNode(Var, tle->expr);
result = bms_add_member(result,
var->varattno - FirstLowInvalidHeapAttributeNumber);
}
* view contains a single base relation.
*/
Assert(list_length(viewquery->jointree->fromlist) == 1);
- rtr = (RangeTblRef *) linitial(viewquery->jointree->fromlist);
- Assert(IsA(rtr, RangeTblRef));
+ rtr = castNode(RangeTblRef, linitial(viewquery->jointree->fromlist));
base_rt_index = rtr->rtindex;
base_rte = rt_fetch(base_rt_index, viewquery->rtable);
foreach(lc1, parsetree->cteList)
{
CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc1);
- Query *ctequery = (Query *) cte->ctequery;
+ Query *ctequery = castNode(Query, cte->ctequery);
List *newstuff;
- Assert(IsA(ctequery, Query));
-
if (ctequery->commandType == CMD_SELECT)
continue;
if (list_length(newstuff) == 1)
{
/* Push the single Query back into the CTE node */
- ctequery = (Query *) linitial(newstuff);
- Assert(IsA(ctequery, Query));
+ ctequery = castNode(Query, linitial(newstuff));
/* WITH queries should never be canSetTag */
Assert(!ctequery->canSetTag);
cte->ctequery = (Node *) ctequery;
Node *
TemporalTransform(int32 max_precis, Node *node)
{
- FuncExpr *expr = (FuncExpr *) node;
+ FuncExpr *expr = castNode(FuncExpr, node);
Node *ret = NULL;
Node *typmod;
- Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);
Datum
numeric_transform(PG_FUNCTION_ARGS)
{
- FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
+ FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
- Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);
List *argdefaults;
str = TextDatumGetCString(proargdefaults);
- argdefaults = (List *) stringToNode(str);
- Assert(IsA(argdefaults, List));
+ argdefaults = castNode(List, stringToNode(str));
pfree(str);
nextargdefault = list_head(argdefaults);
/* nlackdefaults counts only *input* arguments lacking defaults */
}
str = TextDatumGetCString(proargdefaults);
- argdefaults = (List *) stringToNode(str);
- Assert(IsA(argdefaults, List));
+ argdefaults = castNode(List, stringToNode(str));
pfree(str);
proc = (Form_pg_proc) GETSTRUCT(proctup);
appendStringInfoString(buf, "(alternatives: ");
foreach(lc, asplan->subplans)
{
- SubPlan *splan = (SubPlan *) lfirst(lc);
+ SubPlan *splan = castNode(SubPlan, lfirst(lc));
- Assert(IsA(splan, SubPlan));
if (splan->useHashTable)
appendStringInfo(buf, "hashed %s", splan->plan_name);
else
get_rule_expr((Node *) linitial(xexpr->args),
context, true);
- con = (Const *) lsecond(xexpr->args);
- Assert(IsA(con, Const));
+ con = castNode(Const, lsecond(xexpr->args));
Assert(!con->constisnull);
if (DatumGetBool(con->constvalue))
appendStringInfoString(buf,
else
get_rule_expr((Node *) con, context, false);
- con = (Const *) lthird(xexpr->args);
- Assert(IsA(con, Const));
+ con = castNode(Const, lthird(xexpr->args));
if (con->constisnull)
/* suppress STANDALONE NO VALUE */ ;
else
*/
if (DO_AGGSPLIT_COMBINE(aggref->aggsplit))
{
- TargetEntry *tle = linitial(aggref->args);
+ TargetEntry *tle = castNode(TargetEntry, linitial(aggref->args));
Assert(list_length(aggref->args) == 1);
- Assert(IsA(tle, TargetEntry));
resolve_special_varno((Node *) tle->expr, context, original_aggref,
get_agg_combine_expr);
return;
sep = "";
foreach(l, ((BoolExpr *) sublink->testexpr)->args)
{
- OpExpr *opexpr = (OpExpr *) lfirst(l);
+ OpExpr *opexpr = castNode(OpExpr, lfirst(l));
- Assert(IsA(opexpr, OpExpr));
appendStringInfoString(buf, sep);
get_rule_expr(linitial(opexpr->args), context, true);
if (!opname)
forboth(lcc, path->indexquals, lci, path->indexqualcols)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lcc);
+ RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lcc));
int indexcol = lfirst_int(lci);
Expr *clause;
Node *leftop,
*rightop;
IndexQualInfo *qinfo;
- Assert(IsA(rinfo, RestrictInfo));
clause = rinfo->clause;
qinfo = (IndexQualInfo *) palloc(sizeof(IndexQualInfo));
Datum
interval_transform(PG_FUNCTION_ARGS)
{
- FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
+ FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
- Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);
Datum
varbit_transform(PG_FUNCTION_ARGS)
{
- FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
+ FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
- Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);
Datum
varchar_transform(PG_FUNCTION_ARGS)
{
- FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
+ FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
- Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);
}
else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
{
- A_Const *con = (A_Const *) linitial(stmt->args);
+ A_Const *con = castNode(A_Const, linitial(stmt->args));
if (stmt->is_local)
ereport(ERROR,
errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
- Assert(IsA(con, A_Const));
Assert(nodeTag(&con->val) == T_String);
ImportSnapshot(strVal(&con->val));
}
Datum
plpgsql_inline_handler(PG_FUNCTION_ARGS)
{
- InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
+ InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
PLpgSQL_function *func;
FunctionCallInfoData fake_fcinfo;
FmgrInfo flinfo;
Datum retval;
int rc;
- Assert(IsA(codeblock, InlineCodeBlock));
-
/*
* Connect to SPI manager
*/
foreach(cell, cmd->d.alterTable.subcmds)
{
CollectedATSubcmd *sub = lfirst(cell);
- AlterTableCmd *subcmd = (AlterTableCmd *) sub->parsetree;
+ AlterTableCmd *subcmd = castNode(AlterTableCmd, sub->parsetree);
const char *strtype;
- Assert(IsA(subcmd, AlterTableCmd));
-
switch (subcmd->subtype)
{
case AT_AddColumn: