-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type
attribute to A_CONST nodes.
#5
Conversation
This fixes an issue where BitString's cannot be deparsed properly because they cannot be distinguished from normal strings. Example: SELECT B'0101' and SELECT '0101' This patch adds a `type` which outputs the integer node tag so that callers can be certain of the type of the constant given the limitations of the serialization format (JSON). This also fixes a bug where `BitString`s were being dumped as invalid JSON: ``` { "val": b0101 } ```
@@ -140,7 +140,7 @@ index 0000000..eaded0f | |||
+static void | |||
+_outToken(StringInfo str, const char *s) | |||
+{ | |||
+ if (s == NULL || *s == '\0') | |||
+ if (s == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats the fix for #3 - correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, that's a fix for #3. It was such a trivial change I just included it here ;)
Looks good! I'll do some quick testing with the Ruby library, to make sure this doesn't confuse any callers - looking to merge this later today. |
@lfittl one possible thing to consider with the bitstrings is if the leading char should be stripped. Current PR:
The lib could either return |
@zhm Good point - lets maybe do the version without Also, looking at the output, do you think we can output the type as a readable name instead? (might make parsing more reliable across versions) |
👍 for readable type names! |
I updated the PR to use strings instead of enums for the type names. We now have:
Also I think we need to leave the SELECT B'0101`
> b0101 SELECT X'EFFF`
> xEFFF |
Also note that I don't think bitstrings are particularly useful to most people, just trying to get some random SQL scripts to parse/deparse ;) I suppose it's possible that Postgres could introduce new value types, so maybe this all makes sense anyways. |
@lfittl also, are there any other scenarios where the caller would care about the type of the |
@zhm Patch looks good! From my quick grep-ing through the node definitions, it looks like If we wanted to put it into all value nodes, we could consider only outputting the type if its not string (and maybe also if its not null), to avoid bloating the tree. But I'll merge this as-is, we can revisit later if needed. |
Add `type` attribute to A_CONST nodes.
This fixes an issue where BitString's cannot be deparsed properly
because they cannot be distinguished from normal strings.
Example:
and
This patch adds a
type
which outputs the integer node tag so thatcallers can be certain of the type of the constant given the limitations
of the serialization format (JSON). This also fixes a bug where
BitString
s were being dumped as invalid JSON: