Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

makefuncs.h File Reference

#include "nodes/parsenodes.h"
Include dependency graph for makefuncs.h:

Go to the source code of this file.

Functions

A_Expr * makeA_Expr (A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr, int location)
A_Expr * makeSimpleA_Expr (A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
Var * makeVar (Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Var * makeVarFromTargetEntry (Index varno, TargetEntry *tle)
Var * makeWholeRowVar (RangeTblEntry *rte, Index varno, Index varlevelsup, bool allowScalar)
TargetEntry * makeTargetEntry (Expr *expr, AttrNumber resno, char *resname, bool resjunk)
TargetEntry * flatCopyTargetEntry (TargetEntry *src_tle)
FromExpr * makeFromExpr (List *fromlist, Node *quals)
Const * makeConst (Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Const * makeNullConst (Oid consttype, int32 consttypmod, Oid constcollid)
Node * makeBoolConst (bool value, bool isnull)
Expr * makeBoolExpr (BoolExprType boolop, List *args, int location)
Alias * makeAlias (const char *aliasname, List *colnames)
RelabelType * makeRelabelType (Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
RangeVar * makeRangeVar (char *schemaname, char *relname, int location)
TypeName * makeTypeName (char *typnam)
TypeName * makeTypeNameFromNameList (List *names)
TypeName * makeTypeNameFromOid (Oid typeOid, int32 typmod)
FuncExpr * makeFuncExpr (Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
DefElem * makeDefElem (char *name, Node *arg)
DefElem * makeDefElemExtended (char *nameSpace, char *name, Node *arg, DefElemAction defaction)

Function Documentation

TargetEntry* flatCopyTargetEntry ( TargetEntry *  src_tle  ) 

Definition at line 245 of file makefuncs.c.

References Assert, IsA, and makeNode.

Referenced by expand_targetlist(), process_matched_tle(), rewriteTargetListIU(), set_dummy_tlist_references(), and set_upper_references().

{
    TargetEntry *tle = makeNode(TargetEntry);

    Assert(IsA(src_tle, TargetEntry));
    memcpy(tle, src_tle, sizeof(TargetEntry));
    return tle;
}

A_Expr* makeA_Expr ( A_Expr_Kind  kind,
List *  name,
Node *  lexpr,
Node *  rexpr,
int  location 
)

Definition at line 30 of file makefuncs.c.

References A_Expr::kind, A_Expr::lexpr, A_Expr::location, makeNode, A_Expr::name, and A_Expr::rexpr.

Referenced by transformJoinUsingClause().

{
    A_Expr     *a = makeNode(A_Expr);

    a->kind = kind;
    a->name = name;
    a->lexpr = lexpr;
    a->rexpr = rexpr;
    a->location = location;
    return a;
}

Alias* makeAlias ( const char *  aliasname,
List *  colnames 
)
Node* makeBoolConst ( bool  value,
bool  isnull 
)

Definition at line 323 of file makefuncs.c.

References BoolGetDatum, BOOLOID, InvalidOid, and makeConst().

Referenced by clause_selectivity(), create_append_plan(), eval_const_expressions_mutator(), expand_boolean_index_clause(), inheritance_planner(), make_ands_explicit(), make_row_distinct_op(), negate_clause(), and transformAExprOf().

{
    /* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
    return (Node *) makeConst(BOOLOID, -1, InvalidOid, 1,
                              BoolGetDatum(value), isnull, true);
}

Expr* makeBoolExpr ( BoolExprType  boolop,
List *  args,
int  location 
)
Const* makeConst ( Oid  consttype,
int32  consttypmod,
Oid  constcollid,
int  constlen,
Datum  constvalue,
bool  constisnull,
bool  constbyval 
)
DefElem* makeDefElem ( char *  name,
Node *  arg 
)
DefElem* makeDefElemExtended ( char *  nameSpace,
char *  name,
Node *  arg,
DefElemAction  defaction 
)

Definition at line 499 of file makefuncs.c.

References DefElem::arg, DefElem::defaction, DefElem::defname, DefElem::defnamespace, and makeNode.

{
    DefElem    *res = makeNode(DefElem);

    res->defnamespace = nameSpace;
    res->defname = name;
    res->arg = arg;
    res->defaction = defaction;

    return res;
}

FromExpr* makeFromExpr ( List *  fromlist,
Node *  quals 
)
FuncExpr* makeFuncExpr ( Oid  funcid,
Oid  rettype,
List *  args,
Oid  funccollid,
Oid  inputcollid,
CoercionForm  fformat 
)

Definition at line 455 of file makefuncs.c.

References FuncExpr::args, FuncExpr::funccollid, FuncExpr::funcformat, FuncExpr::funcid, FuncExpr::funcresulttype, FuncExpr::funcretset, FuncExpr::funcvariadic, FuncExpr::inputcollid, FuncExpr::location, and makeNode.

Referenced by build_aggregate_fnexprs(), and build_coercion_expression().

{
    FuncExpr   *funcexpr;

    funcexpr = makeNode(FuncExpr);
    funcexpr->funcid = funcid;
    funcexpr->funcresulttype = rettype;
    funcexpr->funcretset = false;       /* only allowed case here */
    funcexpr->funcvariadic = false;     /* only allowed case here */
    funcexpr->funcformat = fformat;
    funcexpr->funccollid = funccollid;
    funcexpr->inputcollid = inputcollid;
    funcexpr->args = args;
    funcexpr->location = -1;

    return funcexpr;
}

Const* makeNullConst ( Oid  consttype,
int32  consttypmod,
Oid  constcollid 
)

Definition at line 303 of file makefuncs.c.

References get_typlenbyval(), and makeConst().

Referenced by AcquireRewriteLocks(), ATExecAddColumn(), coerce_record_to_complex(), eval_const_expressions_mutator(), evaluate_function(), ExecInitExpr(), expandTupleDesc(), ReplaceVarsFromTargetList_callback(), and transformAssignedExpr().

{
    int16       typLen;
    bool        typByVal;

    get_typlenbyval(consttype, &typLen, &typByVal);
    return makeConst(consttype,
                     consttypmod,
                     constcollid,
                     (int) typLen,
                     (Datum) 0,
                     true,
                     typByVal);
}

RangeVar* makeRangeVar ( char *  schemaname,
char *  relname,
int  location 
)
RelabelType* makeRelabelType ( Expr *  arg,
Oid  rtype,
int32  rtypmod,
Oid  rcollid,
CoercionForm  rformat 
)
A_Expr* makeSimpleA_Expr ( A_Expr_Kind  kind,
char *  name,
Node *  lexpr,
Node *  rexpr,
int  location 
)

Definition at line 48 of file makefuncs.c.

References A_Expr::kind, A_Expr::lexpr, list_make1, A_Expr::location, makeNode, makeString(), A_Expr::name, and A_Expr::rexpr.

Referenced by transformCaseExpr(), and transformJoinUsingClause().

{
    A_Expr     *a = makeNode(A_Expr);

    a->kind = kind;
    a->name = list_make1(makeString((char *) name));
    a->lexpr = lexpr;
    a->rexpr = rexpr;
    a->location = location;
    return a;
}

TargetEntry* makeTargetEntry ( Expr *  expr,
AttrNumber  resno,
char *  resname,
bool  resjunk 
)
TypeName* makeTypeName ( char *  typnam  ) 

Definition at line 410 of file makefuncs.c.

References list_make1, makeString(), and makeTypeNameFromNameList().

Referenced by plpgsql_parse_wordtype().

TypeName* makeTypeNameFromNameList ( List *  names  ) 
TypeName* makeTypeNameFromOid ( Oid  typeOid,
int32  typmod 
)
Var* makeVar ( Index  varno,
AttrNumber  varattno,
Oid  vartype,
int32  vartypmod,
Oid  varcollid,
Index  varlevelsup 
)

Definition at line 66 of file makefuncs.c.

References Var::location, makeNode, Var::varattno, Var::varcollid, Var::varlevelsup, Var::varno, Var::varnoold, Var::varoattno, Var::vartype, and Var::vartypmod.

Referenced by ATPrepAlterColumnType(), build_index_tlist(), build_physical_tlist(), eval_const_expressions_mutator(), expand_targetlist(), expandRTE(), expandTupleDesc(), fix_indexqual_operand(), generate_append_tlist(), generate_setop_tlist(), get_relation_constraints(), make_inh_translation_list(), make_var(), makeVarFromTargetEntry(), makeWholeRowVar(), postgresAddForeignUpdateTargets(), preprocess_targetlist(), rewriteTargetListIU(), rewriteTargetListUD(), set_dummy_tlist_references(), and transformSetOperationStmt().

{
    Var        *var = makeNode(Var);

    var->varno = varno;
    var->varattno = varattno;
    var->vartype = vartype;
    var->vartypmod = vartypmod;
    var->varcollid = varcollid;
    var->varlevelsup = varlevelsup;

    /*
     * Since few if any routines ever create Var nodes with varnoold/varoattno
     * different from varno/varattno, we don't provide separate arguments for
     * them, but just initialize them to the given varno/varattno. This
     * reduces code clutter and chance of error for most callers.
     */
    var->varnoold = varno;
    var->varoattno = varattno;

    /* Likewise, we just set location to "unknown" here */
    var->location = -1;

    return var;
}

Var* makeVarFromTargetEntry ( Index  varno,
TargetEntry *  tle 
)
Var* makeWholeRowVar ( RangeTblEntry *  rte,
Index  varno,
Index  varlevelsup,
bool  allowScalar 
)

Definition at line 131 of file makefuncs.c.

References elog, ERROR, exprCollation(), exprType(), RangeTblEntry::funcexpr, get_rel_type_id(), InvalidAttrNumber, InvalidOid, makeVar(), OidIsValid, RECORDOID, RangeTblEntry::relid, RTE_FUNCTION, RTE_RELATION, RangeTblEntry::rtekind, and type_is_rowtype().

Referenced by preprocess_targetlist(), rewriteTargetListUD(), and transformWholeRowRef().

{
    Var        *result;
    Oid         toid;

    switch (rte->rtekind)
    {
        case RTE_RELATION:
            /* relation: the rowtype is a named composite type */
            toid = get_rel_type_id(rte->relid);
            if (!OidIsValid(toid))
                elog(ERROR, "could not find type OID for relation %u",
                     rte->relid);
            result = makeVar(varno,
                             InvalidAttrNumber,
                             toid,
                             -1,
                             InvalidOid,
                             varlevelsup);
            break;
        case RTE_FUNCTION:
            toid = exprType(rte->funcexpr);
            if (type_is_rowtype(toid))
            {
                /* func returns composite; same as relation case */
                result = makeVar(varno,
                                 InvalidAttrNumber,
                                 toid,
                                 -1,
                                 InvalidOid,
                                 varlevelsup);
            }
            else if (allowScalar)
            {
                /* func returns scalar; just return its output as-is */
                result = makeVar(varno,
                                 1,
                                 toid,
                                 -1,
                                 exprCollation(rte->funcexpr),
                                 varlevelsup);
            }
            else
            {
                /* func returns scalar, but we want a composite result */
                result = makeVar(varno,
                                 InvalidAttrNumber,
                                 RECORDOID,
                                 -1,
                                 InvalidOid,
                                 varlevelsup);
            }
            break;
        default:

            /*
             * RTE is a join, subselect, or VALUES.  We represent this as a
             * whole-row Var of RECORD type. (Note that in most cases the Var
             * will be expanded to a RowExpr during planning, but that is not
             * our concern here.)
             */
            result = makeVar(varno,
                             InvalidAttrNumber,
                             RECORDOID,
                             -1,
                             InvalidOid,
                             varlevelsup);
            break;
    }

    return result;
}