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

string_to_array type function to split a string on a delimiter, returning an array. #7555

Closed
casperhart opened this issue Sep 14, 2023 · 1 comment · Fixed by #7577
Closed
Labels
enhancement New feature or request

Comments

@casperhart
Copy link
Contributor

casperhart commented Sep 14, 2023

Is your feature request related to a problem or challenge?

I would like to take a string like "a / b / c" and return [a, b, c] as an array.

Describe the solution you'd like

A function like the Postgres string_to_array function. E.g.:

select 'a / b / c' as original, string_to_array('a / b / c', ' / ') as array
+-----------+-----------+
| original  | array     |
+-----------+-----------+
| a / b / c | [a, b, c] |
+-----------+-----------+

More generally:

string_to_array(string, delimiter [, null_value])

Describe alternatives you've considered

split_part can split a string and return a single part based on the position, but if the number of delimiters in the string isn't known in advance, this doesn't work well.
I haven't seen any other functions that would allow this, but I may have overlooked something.

Additional context

I am preparing a PR for this, but wanted to create an issue first. For example, it would be good to know:

  • is the postgres function string_to_array a good one to model this off, or if a different SQL flavour is preferred.
  • would this be better created as a string function or an array function. I think string function, but I'm not sure
  • if I've totally overlooked something that solves this problem already, or if someone else is working on something similar
  • whether this will be a welcome addition, or if there is a plan for something different
@casperhart casperhart added the enhancement New feature or request label Sep 14, 2023
@alamb
Copy link
Contributor

alamb commented Sep 16, 2023

I think this feature sounds reasonable -- thank you for the PR

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

Successfully merging a pull request may close this issue.

2 participants