mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user