Skip to content
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

Merged
merged 1 commit into from
Jan 25, 2023

Conversation

msirek
Copy link
Contributor

@msirek msirek commented Jan 25, 2023

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.

@msirek msirek requested review from yuzefovich and a team January 25, 2023 02:24
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :lgtm: 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: :shipit: 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.
Copy link
Contributor Author

@msirek msirek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Reviewable status: :shipit: 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

Copy link
Contributor Author

@msirek msirek left a 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: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @yuzefovich)

@craig
Copy link
Contributor

craig bot commented Jan 25, 2023

Build succeeded:

@blathers-crl
Copy link

blathers-crl bot commented Jan 25, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GoldenGate Parallel Replicat Migration fails on INT2VECTOR conversion
3 participants