mirror of
https://github.com/postgres/postgres.git
synced 2025-11-29 23:43:17 +03:00
Add Boolean node
Before, SQL-level boolean constants were represented by a string with a cast, and internal Boolean values in DDL commands were usually represented by Integer nodes. This takes the place of both of these uses, making the intent clearer and having some amount of type safety. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/8c1a2e37-c68d-703c-5a83-7a6077f4f997@enterprisedb.com
This commit is contained in:
@@ -2750,6 +2750,9 @@ _copyA_Const(const A_Const *from)
|
||||
case T_Float:
|
||||
COPY_STRING_FIELD(val.fval.fval);
|
||||
break;
|
||||
case T_Boolean:
|
||||
COPY_SCALAR_FIELD(val.boolval.boolval);
|
||||
break;
|
||||
case T_String:
|
||||
COPY_STRING_FIELD(val.sval.sval);
|
||||
break;
|
||||
@@ -4949,6 +4952,16 @@ _copyFloat(const Float *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static Boolean *
|
||||
_copyBoolean(const Boolean *from)
|
||||
{
|
||||
Boolean *newnode = makeNode(Boolean);
|
||||
|
||||
COPY_SCALAR_FIELD(boolval);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static String *
|
||||
_copyString(const String *from)
|
||||
{
|
||||
@@ -5356,6 +5369,9 @@ copyObjectImpl(const void *from)
|
||||
case T_Float:
|
||||
retval = _copyFloat(from);
|
||||
break;
|
||||
case T_Boolean:
|
||||
retval = _copyBoolean(from);
|
||||
break;
|
||||
case T_String:
|
||||
retval = _copyString(from);
|
||||
break;
|
||||
|
||||
@@ -3138,6 +3138,14 @@ _equalFloat(const Float *a, const Float *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalBoolean(const Boolean *a, const Boolean *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(boolval);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalString(const String *a, const String *b)
|
||||
{
|
||||
@@ -3374,6 +3382,9 @@ equal(const void *a, const void *b)
|
||||
case T_Float:
|
||||
retval = _equalFloat(a, b);
|
||||
break;
|
||||
case T_Boolean:
|
||||
retval = _equalBoolean(a, b);
|
||||
break;
|
||||
case T_String:
|
||||
retval = _equalString(a, b);
|
||||
break;
|
||||
|
||||
@@ -3577,6 +3577,7 @@ raw_expression_tree_walker(Node *node,
|
||||
case T_SQLValueFunction:
|
||||
case T_Integer:
|
||||
case T_Float:
|
||||
case T_Boolean:
|
||||
case T_String:
|
||||
case T_BitString:
|
||||
case T_ParamRef:
|
||||
|
||||
@@ -3434,6 +3434,12 @@ _outFloat(StringInfo str, const Float *node)
|
||||
appendStringInfoString(str, node->fval);
|
||||
}
|
||||
|
||||
static void
|
||||
_outBoolean(StringInfo str, const Boolean *node)
|
||||
{
|
||||
appendStringInfoString(str, node->boolval ? "true" : "false");
|
||||
}
|
||||
|
||||
static void
|
||||
_outString(StringInfo str, const String *node)
|
||||
{
|
||||
@@ -3846,6 +3852,8 @@ outNode(StringInfo str, const void *obj)
|
||||
_outInteger(str, (Integer *) obj);
|
||||
else if (IsA(obj, Float))
|
||||
_outFloat(str, (Float *) obj);
|
||||
else if (IsA(obj, Boolean))
|
||||
_outBoolean(str, (Boolean *) obj);
|
||||
else if (IsA(obj, String))
|
||||
_outString(str, (String *) obj);
|
||||
else if (IsA(obj, BitString))
|
||||
|
||||
@@ -235,7 +235,7 @@ debackslash(const char *token, int length)
|
||||
* nodeTokenType -
|
||||
* returns the type of the node token contained in token.
|
||||
* It returns one of the following valid NodeTags:
|
||||
* T_Integer, T_Float, T_String, T_BitString
|
||||
* T_Integer, T_Float, T_Boolean, T_String, T_BitString
|
||||
* and some of its own:
|
||||
* RIGHT_PAREN, LEFT_PAREN, LEFT_BRACE, OTHER_TOKEN
|
||||
*
|
||||
@@ -283,6 +283,8 @@ nodeTokenType(const char *token, int length)
|
||||
retval = RIGHT_PAREN;
|
||||
else if (*token == '{')
|
||||
retval = LEFT_BRACE;
|
||||
else if (strcmp(token, "true") == 0 || strcmp(token, "false") == 0)
|
||||
retval = T_Boolean;
|
||||
else if (*token == '"' && length > 1 && token[length - 1] == '"')
|
||||
retval = T_String;
|
||||
else if (*token == 'b')
|
||||
@@ -298,7 +300,7 @@ nodeTokenType(const char *token, int length)
|
||||
*
|
||||
* This routine applies some semantic knowledge on top of the purely
|
||||
* lexical tokenizer pg_strtok(). It can read
|
||||
* * Value token nodes (integers, floats, or strings);
|
||||
* * Value token nodes (integers, floats, booleans, or strings);
|
||||
* * General nodes (via parseNodeString() from readfuncs.c);
|
||||
* * Lists of the above;
|
||||
* * Lists of integers or OIDs.
|
||||
@@ -438,6 +440,9 @@ nodeRead(const char *token, int tok_len)
|
||||
result = (Node *) makeFloat(fval);
|
||||
}
|
||||
break;
|
||||
case T_Boolean:
|
||||
result = (Node *) makeBoolean(token[0] == 't');
|
||||
break;
|
||||
case T_String:
|
||||
/* need to remove leading and trailing quotes, and backslashes */
|
||||
result = (Node *) makeString(debackslash(token + 1, tok_len - 2));
|
||||
|
||||
@@ -42,6 +42,18 @@ makeFloat(char *numericStr)
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
* makeBoolean
|
||||
*/
|
||||
Boolean *
|
||||
makeBoolean(bool val)
|
||||
{
|
||||
Boolean *v = makeNode(Boolean);
|
||||
|
||||
v->boolval = val;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
* makeString
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user