-
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
builtins: array_to_string should traverse nested arrays #95802
Conversation
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.
Nice! Let's add backport labels to this since it seems like a pretty safe fix.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @msirek)
pkg/sql/sem/builtins/builtins.go
line 9876 at r1 (raw file):
} else { if nestedArray, ok := arr.Array[i].(*tree.DArray); ok { arrayToStringHelper(evalCtx, nestedArray, delim, nullStr, f)
nit: consider adding a quick comment that we want to "unpack" nested arrays to be consistent with postgres.
Fixes cockroachdb#95588 In Postgres, `array_to_string` traverses nested arrays and prints their contents. In CRDB, the nested array structures are printed out. For example, `SELECT array_to_string(ARRAY[ARRAY[ARRAY[5,6], ARRAY[2,3]]], ' ');` CRDB Result: `ARRAY[ARRAY[5:::INT8,6:::INT8],ARRAY[2:::INT8,3:::INT8]]` Postgres Result: `5 6 2 3` This fix brings the behavior of `array_to_string` in line with Postgres, and avoids printing the nested ARRAY structures. Some tools like GoldenGate rely on Postgres-compatible behavior of `array_to_string` for proper functioning. Release note (bug fix): This patch fixes the array_to_string built-in function so that nested arrays are traversed without printing 'ARRAY' at each nesting level.
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.
Added
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @yuzefovich)
pkg/sql/sem/builtins/builtins.go
line 9876 at r1 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit: consider adding a quick comment that we want to "unpack" nested arrays to be consistent with postgres.
Done
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.
TFTR!
bors r=yuzefovich
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @yuzefovich)
Build succeeded: |
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from eb88269 to blathers/backport-release-22.1-95802: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 22.1.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
Fixes #95588
In Postgres,
array_to_string
traverses nested arrays and prints their contents. In CRDB, the nested array structures are printed out. For example,SELECT array_to_string(ARRAY[ARRAY[ARRAY[5,6], ARRAY[2,3]]], ' ');
CRDB Result:
ARRAY[ARRAY[5:::INT8,6:::INT8],ARRAY[2:::INT8,3:::INT8]]
Postgres Result:5 6 2 3
This fix brings the behavior of
array_to_string
in line with Postgres, and avoids printing the nested ARRAY structures.Some tools like GoldenGate rely on Postgres-compatible behavior of
array_to_string
for proper functioning.Release note (bug fix): This patch fixes the array_to_string built-in function so that nested arrays are traversed without printing 'ARRAY' at each nesting level.