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

sql: support to array_agg() for arrays #117756

Closed
sean- opened this issue Jan 13, 2024 · 1 comment · Fixed by #117838
Closed

sql: support to array_agg() for arrays #117756

sean- opened this issue Jan 13, 2024 · 1 comment · Fixed by #117838
Assignees
Labels
A-sql-builtins SQL built-in functions and semantics thereof. A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) E-quick-win Likely to be a quick win for someone experienced. O-support Originated from a customer P-2 Issues/test failures with a fix SLA of 3 months T-sql-queries SQL Queries Team

Comments

@sean-
Copy link
Collaborator

sean- commented Jan 13, 2024

Is your feature request related to a problem? Please describe.

Minimum reproduction:

        => SELECT version();
┌───────────────────────────────────────────────────────────────────────────────────────────┐
│                                          version                                          │
├───────────────────────────────────────────────────────────────────────────────────────────┤
│ CockroachDB CCL v22.2.17 (aarch64-unknown-linux-gnu, built 2023/11/20 16:09:42, go1.19.6) │
└───────────────────────────────────────────────────────────────────────────────────────────┘
(1 row)
        => CREATE TABLE __test_array_agg(a TEXT PRIMARY KEY, b TEXT, c TEXT);
CREATE TABLE
        => SELECT array_agg(array[a, b, c]) FROM __test_array_agg;
ERROR:  unknown signature: array_agg(string[])

Describe alternatives you've considered

I was trying to come up with workarounds and got a close approximation, but it returns record[] instead of text[] like postgres does.

select array_agg(t.*) from __test_array_agg as t;

Jira issue: CRDB-35334

@sean- sean- added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Jan 13, 2024
@rharding6373 rharding6373 removed their assignment Jan 13, 2024
@rafiss rafiss added T-sql-queries SQL Queries Team A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-builtins SQL built-in functions and semantics thereof. labels Jan 13, 2024
@yuzefovich yuzefovich added O-support Originated from a customer E-quick-win Likely to be a quick win for someone experienced. P-2 Issues/test failures with a fix SLA of 3 months labels Jan 16, 2024
@yuzefovich yuzefovich self-assigned this Jan 16, 2024
@yuzefovich yuzefovich changed the title Add support to array_agg() for arrays sql: support to array_agg() for arrays Jan 16, 2024
@yuzefovich
Copy link
Member

We already have a somewhat-related custom array_cat_agg which behaves differently from array_agg with arrays in PG, for example:

CREATE TABLE __test_array_agg(a TEXT PRIMARY KEY, b TEXT, c TEXT);
INSERT INTO __test_array_agg VALUES ('a', 'b', 'c'), ('aa', 'bb', 'cc'), ('aaa', 'bbb', 'ccc');

PG:

SELECT array_agg(array[a, b, c]) FROM __test_array_agg;
             array_agg              
------------------------------------
 {{a,b,c},{aa,bb,cc},{aaa,bbb,ccc}}

CRDB:

SELECT array_cat_agg(array[a, b, c]) FROM __test_array_agg;                                                                     
         array_cat_agg
--------------------------------
  {a,b,c,aa,bb,cc,aaa,bbb,ccc}

I do have a prototype in #117838 that would expand array_agg to support arrays as inputs. There is a minor complication that we, generally speaking, don't support multi-dimensional arrays (#32552), so it might be somewhat contentious on whether that change will get merged (evaluation of array_agg on arrays internally uses nested arrays as well as its result is a nested array).

@craig craig bot closed this as completed in 2a4e6b8 Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-builtins SQL built-in functions and semantics thereof. A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) E-quick-win Likely to be a quick win for someone experienced. O-support Originated from a customer P-2 Issues/test failures with a fix SLA of 3 months T-sql-queries SQL Queries Team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants