diff options
| author | Peter Eisentraut | 2021-09-09 05:58:12 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2021-09-09 06:36:53 +0000 |
| commit | 639a86e36aaecb84faaf941dcd0b183ba0aba9e9 (patch) | |
| tree | 2b523f247bf373ae61fcff5fb0bf938c6c5bdc07 /src/backend/nodes/outfuncs.c | |
| parent | cbdf75bf8053f88bbae6b307f34ab057424a370f (diff) | |
Remove Value node struct
The Value node struct is a weird construct. It is its own node type,
but most of the time, it actually has a node type of Integer, Float,
String, or BitString. As a consequence, the struct name and the node
type don't match most of the time, and so it has to be treated
specially a lot. There doesn't seem to be any value in the special
construct. There is very little code that wants to accept all Value
variants but nothing else (and even if it did, this doesn't provide
any convenient way to check it), and most code wants either just one
particular node type (usually String), or it accepts a broader set of
node types besides just Value.
This change removes the Value struct and node type and replaces them
by separate Integer, Float, String, and BitString node types that are
proper node types and structs of their own and behave mostly like
normal node types.
Also, this removes the T_Null node tag, which was previously also a
possible variant of Value but wasn't actually used outside of the
Value contained in A_Const. Replace that by an isnull field in
A_Const.
Reviewed-by: Dagfinn Ilmari Mannsåker <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/backend/nodes/outfuncs.c')
| -rw-r--r-- | src/backend/nodes/outfuncs.c | 93 |
1 files changed, 47 insertions, 46 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 87561cbb6f1..36e618611fd 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -3414,44 +3414,39 @@ _outA_Expr(StringInfo str, const A_Expr *node) } static void -_outValue(StringInfo str, const Value *node) +_outInteger(StringInfo str, const Integer *node) { - switch (node->type) - { - case T_Integer: - appendStringInfo(str, "%d", node->val.ival); - break; - case T_Float: + appendStringInfo(str, "%d", node->val); +} - /* - * We assume the value is a valid numeric literal and so does not - * need quoting. - */ - appendStringInfoString(str, node->val.str); - break; - case T_String: - - /* - * We use outToken to provide escaping of the string's content, - * but we don't want it to do anything with an empty string. - */ - appendStringInfoChar(str, '"'); - if (node->val.str[0] != '\0') - outToken(str, node->val.str); - appendStringInfoChar(str, '"'); - break; - case T_BitString: - /* internal representation already has leading 'b' */ - appendStringInfoString(str, node->val.str); - break; - case T_Null: - /* this is seen only within A_Const, not in transformed trees */ - appendStringInfoString(str, "NULL"); - break; - default: - elog(ERROR, "unrecognized node type: %d", (int) node->type); - break; - } +static void +_outFloat(StringInfo str, const Float *node) +{ + /* + * We assume the value is a valid numeric literal and so does not + * need quoting. + */ + appendStringInfoString(str, node->val); +} + +static void +_outString(StringInfo str, const String *node) +{ + /* + * We use outToken to provide escaping of the string's content, + * but we don't want it to do anything with an empty string. + */ + appendStringInfoChar(str, '"'); + if (node->val[0] != '\0') + outToken(str, node->val); + appendStringInfoChar(str, '"'); +} + +static void +_outBitString(StringInfo str, const BitString *node) +{ + /* internal representation already has leading 'b' */ + appendStringInfoString(str, node->val); } static void @@ -3491,8 +3486,13 @@ _outA_Const(StringInfo str, const A_Const *node) { WRITE_NODE_TYPE("A_CONST"); - appendStringInfoString(str, " :val "); - _outValue(str, &(node->val)); + if (node->isnull) + appendStringInfoString(str, "NULL"); + else + { + appendStringInfoString(str, " :val "); + outNode(str, &node->val); + } WRITE_LOCATION_FIELD(location); } @@ -3835,14 +3835,15 @@ outNode(StringInfo str, const void *obj) appendStringInfoString(str, "<>"); else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList)) _outList(str, obj); - else if (IsA(obj, Integer) || - IsA(obj, Float) || - IsA(obj, String) || - IsA(obj, BitString)) - { - /* nodeRead does not want to see { } around these! */ - _outValue(str, obj); - } + /* nodeRead does not want to see { } around these! */ + else if (IsA(obj, Integer)) + _outInteger(str, (Integer *) obj); + else if (IsA(obj, Float)) + _outFloat(str, (Float *) obj); + else if (IsA(obj, String)) + _outString(str, (String *) obj); + else if (IsA(obj, BitString)) + _outBitString(str, (BitString *) obj); else { appendStringInfoChar(str, '{'); |
