Header And Logo

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

value.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * value.h
00004  *    interface for Value nodes
00005  *
00006  *
00007  * Copyright (c) 2003-2013, PostgreSQL Global Development Group
00008  *
00009  * src/include/nodes/value.h
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 #ifndef VALUE_H
00015 #define VALUE_H
00016 
00017 #include "nodes/nodes.h"
00018 
00019 /*----------------------
00020  *      Value node
00021  *
00022  * The same Value struct is used for five node types: T_Integer,
00023  * T_Float, T_String, T_BitString, T_Null.
00024  *
00025  * Integral values are actually represented by a machine integer,
00026  * but both floats and strings are represented as strings.
00027  * Using T_Float as the node type simply indicates that
00028  * the contents of the string look like a valid numeric literal.
00029  *
00030  * (Before Postgres 7.0, we used a double to represent T_Float,
00031  * but that creates loss-of-precision problems when the value is
00032  * ultimately destined to be converted to NUMERIC.  Since Value nodes
00033  * are only used in the parsing process, not for runtime data, it's
00034  * better to use the more general representation.)
00035  *
00036  * Note that an integer-looking string will get lexed as T_Float if
00037  * the value is too large to fit in a 'long'.
00038  *
00039  * Nulls, of course, don't need the value part at all.
00040  *----------------------
00041  */
00042 typedef struct Value
00043 {
00044     NodeTag     type;           /* tag appropriately (eg. T_String) */
00045     union ValUnion
00046     {
00047         long        ival;       /* machine integer */
00048         char       *str;        /* string */
00049     }           val;
00050 } Value;
00051 
00052 #define intVal(v)       (((Value *)(v))->val.ival)
00053 #define floatVal(v)     atof(((Value *)(v))->val.str)
00054 #define strVal(v)       (((Value *)(v))->val.str)
00055 
00056 extern Value *makeInteger(long i);
00057 extern Value *makeFloat(char *numericStr);
00058 extern Value *makeString(char *str);
00059 extern Value *makeBitString(char *str);
00060 
00061 #endif   /* VALUE_H */