Skip to content

Commit

Permalink
Merge pull request #5 from zhm/add-type-to-const
Browse files Browse the repository at this point in the history
Add `type` attribute to A_CONST nodes.
  • Loading branch information
lfittl committed Nov 17, 2015
2 parents 5b8475f + 78442e7 commit 95e5e72
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions patches/01_output_nodes_as_json.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ new file mode 100644
index 0000000..eaded0f
--- /dev/null
+++ b/src/backend/nodes/outfuncs_json.c
@@ -0,0 +1,1035 @@
@@ -0,0 +1,1057 @@
+/*-------------------------------------------------------------------------
+ *
+ * outfuncs_json.c
Expand Down Expand Up @@ -140,7 +140,7 @@ index 0000000..eaded0f
+static void
+_outToken(StringInfo str, const char *s)
+{
+ if (s == NULL || *s == '\0')
+ if (s == NULL)
+ {
+ appendStringInfoString(str, "null");
+ return;
Expand Down Expand Up @@ -817,7 +817,7 @@ index 0000000..eaded0f
+ break;
+ case T_BitString:
+ /* internal representation already has leading 'b' */
+ appendStringInfoString(str, value->val.str);
+ _outToken(str, value->val.str);
+ break;
+ case T_Null:
+ /* this is seen only within A_Const, not in transformed trees */
Expand All @@ -834,6 +834,28 @@ index 0000000..eaded0f
+{
+ WRITE_NODE_TYPE("A_CONST");
+
+ appendStringInfoString(str, "\"type\": ");
+ switch (node->val.type)
+ {
+ case T_Integer:
+ appendStringInfoString(str, "\"integer\", ");
+ break;
+ case T_Float:
+ appendStringInfoString(str, "\"float\", ");
+ break;
+ case T_String:
+ appendStringInfoString(str, "\"string\", ");
+ break;
+ case T_BitString:
+ appendStringInfoString(str, "\"bitstring\", ");
+ break;
+ case T_Null:
+ appendStringInfoString(str, "\"null\", ");
+ break;
+ default:
+ elog(ERROR, "unrecognized value type: %d", (int) node->val.type);
+ break;
+ }
+ appendStringInfoString(str, "\"val\": ");
+ _outValue(str, &(node->val));
+ appendStringInfoString(str, ", ");
Expand Down

0 comments on commit 95e5e72

Please sign in to comment.