Header And Logo

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

Functions

define.c File Reference

#include "postgres.h"
#include <ctype.h>
#include <math.h>
#include "catalog/namespace.h"
#include "commands/defrem.h"
#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "parser/scansup.h"
#include "utils/int8.h"
Include dependency graph for define.c:

Go to the source code of this file.

Functions

char * defGetString (DefElem *def)
double defGetNumeric (DefElem *def)
bool defGetBoolean (DefElem *def)
int64 defGetInt64 (DefElem *def)
ListdefGetQualifiedName (DefElem *def)
TypeNamedefGetTypeName (DefElem *def)
int defGetTypeLength (DefElem *def)
DefElemdefWithOids (bool value)

Function Documentation

bool defGetBoolean ( DefElem def  ) 

Definition at line 116 of file define.c.

References DefElem::arg, defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, intVal, nodeTag, NULL, pg_strcasecmp(), and T_Integer.

Referenced by compute_attributes_with_style(), DefineOperator(), DefineType(), dintdict_init(), dsimple_init(), dsynonym_init(), dxsyn_init(), ExplainQuery(), file_fdw_validator(), get_file_fdw_attribute_options(), GetCommandLogLevel(), interpretOidsOption(), postgres_fdw_validator(), postgresGetForeignRelSize(), and ProcessCopyOptions().

{
    /*
     * If no parameter given, assume "true" is meant.
     */
    if (def->arg == NULL)
        return true;

    /*
     * Allow 0, 1, "true", "false", "on", "off"
     */
    switch (nodeTag(def->arg))
    {
        case T_Integer:
            switch (intVal(def->arg))
            {
                case 0:
                    return false;
                case 1:
                    return true;
                default:
                    /* otherwise, error out below */
                    break;
            }
            break;
        default:
            {
                char       *sval = defGetString(def);

                /*
                 * The set of strings accepted here should match up with the
                 * grammar's opt_boolean production.
                 */
                if (pg_strcasecmp(sval, "true") == 0)
                    return true;
                if (pg_strcasecmp(sval, "false") == 0)
                    return false;
                if (pg_strcasecmp(sval, "on") == 0)
                    return true;
                if (pg_strcasecmp(sval, "off") == 0)
                    return false;
            }
            break;
    }
    ereport(ERROR,
            (errcode(ERRCODE_SYNTAX_ERROR),
             errmsg("%s requires a Boolean value",
                    def->defname)));
    return false;               /* keep compiler quiet */
}

int64 defGetInt64 ( DefElem def  ) 

Definition at line 171 of file define.c.

References DefElem::arg, CStringGetDatum, DatumGetInt64, DefElem::defname, DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, int8in(), intVal, nodeTag, NULL, strVal, T_Float, and T_Integer.

Referenced by init_params().

{
    if (def->arg == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("%s requires a numeric value",
                        def->defname)));
    switch (nodeTag(def->arg))
    {
        case T_Integer:
            return (int64) intVal(def->arg);
        case T_Float:

            /*
             * Values too large for int4 will be represented as Float
             * constants by the lexer.  Accept these if they are valid int8
             * strings.
             */
            return DatumGetInt64(DirectFunctionCall1(int8in,
                                         CStringGetDatum(strVal(def->arg))));
        default:
            ereport(ERROR,
                    (errcode(ERRCODE_SYNTAX_ERROR),
                     errmsg("%s requires a numeric value",
                            def->defname)));
    }
    return 0;                   /* keep compiler quiet */
}

double defGetNumeric ( DefElem def  ) 

Definition at line 90 of file define.c.

References DefElem::arg, DefElem::defname, ereport, errcode(), errmsg(), ERROR, floatVal, intVal, nodeTag, NULL, T_Float, and T_Integer.

Referenced by AlterFunction().

{
    if (def->arg == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("%s requires a numeric value",
                        def->defname)));
    switch (nodeTag(def->arg))
    {
        case T_Integer:
            return (double) intVal(def->arg);
        case T_Float:
            return floatVal(def->arg);
        default:
            ereport(ERROR,
                    (errcode(ERRCODE_SYNTAX_ERROR),
                     errmsg("%s requires a numeric value",
                            def->defname)));
    }
    return 0;                   /* keep compiler quiet */
}

List* defGetQualifiedName ( DefElem def  ) 

Definition at line 204 of file define.c.

References DefElem::arg, DefElem::defname, ereport, errcode(), errmsg(), ERROR, list_make1, nodeTag, NULL, T_List, T_String, and T_TypeName.

Referenced by DefineAggregate(), DefineCollation(), DefineOperator(), DefineRange(), DefineTSConfiguration(), DefineTSDictionary(), DefineType(), get_ts_parser_func(), get_ts_template_func(), and init_params().

{
    if (def->arg == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("%s requires a parameter",
                        def->defname)));
    switch (nodeTag(def->arg))
    {
        case T_TypeName:
            return ((TypeName *) def->arg)->names;
        case T_List:
            return (List *) def->arg;
        case T_String:
            /* Allow quoted name for backwards compatibility */
            return list_make1(def->arg);
        default:
            ereport(ERROR,
                    (errcode(ERRCODE_SYNTAX_ERROR),
                     errmsg("argument of %s must be a name",
                            def->defname)));
    }
    return NIL;                 /* keep compiler quiet */
}

char* defGetString ( DefElem def  ) 

Definition at line 49 of file define.c.

References DefElem::arg, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, intVal, NameListToString(), nodeTag, NULL, palloc(), pstrdup(), snprintf(), strVal, T_A_Star, T_Float, T_Integer, T_List, T_String, T_TypeName, and TypeNameToString().

Referenced by check_selective_binary_conversion(), defGetBoolean(), defGetTypeLength(), DefineAggregate(), DefineCollation(), DefineType(), deparseAnalyzeSql(), deparseColumnRef(), deparseRelation(), dintdict_init(), dispell_init(), dsimple_init(), dsnowball_init(), dsynonym_init(), dxsyn_init(), ExplainQuery(), ExplainResultDesc(), ExtractConnectionOptions(), file_fdw_validator(), fileGetOptions(), optionListToArray(), postgres_fdw_validator(), postgresGetForeignRelSize(), ProcessCopyOptions(), prsd_headline(), serialize_deflist(), thesaurus_init(), transformRelOptions(), and unaccent_init().

{
    if (def->arg == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("%s requires a parameter",
                        def->defname)));
    switch (nodeTag(def->arg))
    {
        case T_Integer:
            {
                char       *str = palloc(32);

                snprintf(str, 32, "%ld", (long) intVal(def->arg));
                return str;
            }
        case T_Float:

            /*
             * T_Float values are kept in string form, so this type cheat
             * works (and doesn't risk losing precision)
             */
            return strVal(def->arg);
        case T_String:
            return strVal(def->arg);
        case T_TypeName:
            return TypeNameToString((TypeName *) def->arg);
        case T_List:
            return NameListToString((List *) def->arg);
        case T_A_Star:
            return pstrdup("*");
        default:
            elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
    }
    return NULL;                /* keep compiler quiet */
}

int defGetTypeLength ( DefElem def  ) 

Definition at line 264 of file define.c.

References DefElem::arg, defGetString(), DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, intVal, nodeTag, NULL, pg_strcasecmp(), strVal, T_Float, T_Integer, T_List, T_String, T_TypeName, and TypeNameToString().

Referenced by DefineType().

{
    if (def->arg == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("%s requires a parameter",
                        def->defname)));
    switch (nodeTag(def->arg))
    {
        case T_Integer:
            return intVal(def->arg);
        case T_Float:
            ereport(ERROR,
                    (errcode(ERRCODE_SYNTAX_ERROR),
                     errmsg("%s requires an integer value",
                            def->defname)));
            break;
        case T_String:
            if (pg_strcasecmp(strVal(def->arg), "variable") == 0)
                return -1;      /* variable length */
            break;
        case T_TypeName:
            /* cope if grammar chooses to believe "variable" is a typename */
            if (pg_strcasecmp(TypeNameToString((TypeName *) def->arg),
                              "variable") == 0)
                return -1;      /* variable length */
            break;
        case T_List:
            /* must be an operator name */
            break;
        default:
            elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
    }
    ereport(ERROR,
            (errcode(ERRCODE_SYNTAX_ERROR),
             errmsg("invalid argument for %s: \"%s\"",
                    def->defname, defGetString(def))));
    return 0;                   /* keep compiler quiet */
}

TypeName* defGetTypeName ( DefElem def  ) 

Definition at line 236 of file define.c.

References DefElem::arg, DefElem::defname, ereport, errcode(), errmsg(), ERROR, list_make1, makeTypeNameFromNameList(), nodeTag, NULL, T_String, and T_TypeName.

Referenced by DefineAggregate(), DefineOperator(), DefineRange(), and DefineType().

{
    if (def->arg == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("%s requires a parameter",
                        def->defname)));
    switch (nodeTag(def->arg))
    {
        case T_TypeName:
            return (TypeName *) def->arg;
        case T_String:
            /* Allow quoted typename for backwards compatibility */
            return makeTypeNameFromNameList(list_make1(def->arg));
        default:
            ereport(ERROR,
                    (errcode(ERRCODE_SYNTAX_ERROR),
                     errmsg("argument of %s must be a type name",
                            def->defname)));
    }
    return NULL;                /* keep compiler quiet */
}

DefElem* defWithOids ( bool  value  ) 

Definition at line 308 of file define.c.

References makeDefElem(), and makeInteger().

{
    return makeDefElem("oids", (Node *) makeInteger(value));
}