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

explode-json-array operation #45

Open
fatchat opened this issue Nov 5, 2023 · 1 comment · May be fixed by #46
Open

explode-json-array operation #45

fatchat opened this issue Nov 5, 2023 · 1 comment · May be fixed by #46
Assignees

Comments

@fatchat
Copy link
Contributor

fatchat commented Nov 5, 2023

No description provided.

@fatchat
Copy link
Contributor Author

fatchat commented Nov 5, 2023

Get the columns using

SELECT DISTINCT
  jsonb_object_keys(jsonb_array_elements(data::jsonb)) AS key
FROM your_table;

and then explode into multiple rows with

SELECT
  original_column_1,
  original_column_2,
  jsonb_array_elements(data::jsonb) ->> 'col1' AS col1,
  jsonb_array_elements(data::jsonb) ->> 'col2' AS col2
FROM your_table;

@fatchat fatchat self-assigned this Nov 9, 2023
@fatchat fatchat linked a pull request Nov 9, 2023 that will close this issue
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 a pull request may close this issue.

1 participant