diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-01-14 10:46:49 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-01-17 10:38:23 +0100 |
commit | 941460fcf731a32e6a90691508d5cfa3d1f8eeaf (patch) | |
tree | 2de0be4abcf7db131607ce9ba590a8040c16d6e3 /src/backend/nodes/read.c | |
parent | ca86a63d207aca1f52ff13a1ce13854681d1bbf9 (diff) | |
download | postgresql-941460fcf731a32e6a90691508d5cfa3d1f8eeaf.tar.gz postgresql-941460fcf731a32e6a90691508d5cfa3d1f8eeaf.zip |
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
Diffstat (limited to 'src/backend/nodes/read.c')
-rw-r--r-- | src/backend/nodes/read.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/nodes/read.c b/src/backend/nodes/read.c index 0460aad6ea5..8435203f2bd 100644 --- a/src/backend/nodes/read.c +++ b/src/backend/nodes/read.c @@ -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)); |