-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
tree.FmtExport
does not wrap strings with quotes
#44414
Comments
Once this is fixed, the array parser It seems like the following should be done:
|
I think it's more complicated than that. We used to always quote strings-in-arrays, but then things would break. It turns out that some clients expect strings that don't contain special characters to not get a quote on serialization. Rohan I fear the problem you were set to solve initially is not completely trivial. You're trying to find shortcuts around a fundamental design mistake in our SQL code: we're trying to share parsing routines between at least 3 different "channels" of data:
I am not 100% sure that (1) and (2) even in pg use the same routines. This needs to be double checked. FYI when crdb's own pgwire code and dump/restore were implemented, we did not carry out this analysis and things happened to "just work" (until they didn't. We were in luck perhaps?). I'm also pretty sure that (3) should not be using the same code. In an ideal world, we'd have a library of pairs of builtin functions in SQL like in pg, for byte and text serialization, then we'd use these routines the way they are used in pg. But I'm not sure how much work there is between where we are now and there. |
NB: my comment about what we were originally doing with array refers to the I don't actually know what part of the code would get you
See the expression at the bottom, the ARRAY[] is properly pretty-printed so I'm expecting this should work already. |
Ok, let me try to investigate this more.
If you format an array with |
I believe I'm looking at a simpler problem though -- Just in the case of |
all right carry on 👍 |
44464: sqlbase: add round-trippable export and parsing for arrays and collated strings r=knz a=rohany Work for #44322. Fixes #33429. Fixes #44414. Closes #44669. This PR adds support for ARRAY's and collated strings to be dumped with the `tree.FmtExport` flag, which dumps datums in a string format that can be round-tripped with `sqlbase.ParseDatumStringAs`. This PR additionally performs some code cleanup and renaming around various parsing functions within the `tree` package. In particular, this PR removes the function `tree.ParseStringAs` which was confusingly used sometimes instead of `sqlbase.ParseDatumStringAs` due to it's handling of raw bytes. Instead, we introduce a new function `sqlbase.ParseDatumStringAsWithRawBytes` to be more explicit about when to use one parsing function over the other. Release note (bug fix): This PR fixes bugs around `cockroach dump` and `IMPORT`/`EXPORT` where columns of arrays or collated strings would not be able to be roundtripped from cockroach to the dump and back to cockroach. Co-authored-by: Rohan Yadav <[email protected]>
Found during investigation in #44322.
tree.DNull
and "NULL" serialize to the same string becausetree.FmtExport
does not wrap strings with quotes.ARRAY['hel, lo']
serializes to "ARRAY[hel,lo]", causing a future parse error.The text was updated successfully, but these errors were encountered: