Skip to content

add sql STRING_AGG function #7910

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
universalmind303 opened this issue Oct 23, 2023 · 4 comments
Open

add sql STRING_AGG function #7910

universalmind303 opened this issue Oct 23, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@universalmind303
Copy link
Contributor

Is your feature request related to a problem or challenge?

I'd like to be able to use the equivalent of the postgres function STRING_AGG.

Describe the solution you'd like

select string_agg(first_name, ',') as names from tbl group by last_name

Describe alternatives you've considered

No response

Additional context

a few references on string_agg
https://www.postgresqltutorial.com/postgresql-aggregate-functions/postgresql-string_agg-function/
https://www.postgresql.org/docs/9.0/functions-aggregate.html

@alamb
Copy link
Contributor

alamb commented Oct 23, 2023

FWIW string_agg I think is a table function, which DataFusion doesn't really have great support for yet.

What would you think about implementing something like User Defined Table Functions as a way to implement this? #2177

@universalmind303
Copy link
Contributor Author

FWIW string_agg I think is a table function, which DataFusion doesn't really have great support for yet.

isn't string_agg is an aggregate function similar to ARRAY_AGG which is already a supported function?

string_agg should be functionally equivalent to the combination of already supported functions
concat_ws(<delimiter>, array_agg(<expr>)).

Maybe there's a different string_agg function in other dialects I'm not aware of?

@alamb
Copy link
Contributor

alamb commented Oct 23, 2023

isn't string_agg is an aggregate function similar to ARRAY_AGG which is already a supported function?

You are right, that makes sense. I tried it out:

❯ create table t as values (make_array([1], [2,3], [4])), (make_array([5], [6]));
0 rows in set. Query took 0.001 seconds.

❯ select * from t;
+--------------------+
| column1            |
+--------------------+
| [[1], [2, 3], [4]] |
| [[5], [6]]         |
+--------------------+
2 rows in set. Query took 0.001 seconds.

❯ select array_agg(column1) from t;
+----------------------------------+
| ARRAY_AGG(t.column1)             |
+----------------------------------+
| [[[1], [2, 3], [4]], [[5], [6]]] |
+----------------------------------+
1 row in set. Query took 0.004 seconds.

@haohuaijin
Copy link
Contributor

I want to work on this issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants