0

I need to create an index from a query that uses json_array_elements()

SELECT *, json_array_elements(nested_json_as_text::json) as elements FROM my_table

Since the json contains multiple elements, the result is that the original index is now duplicated across rows and no longer unique.

I am not very familiar with creating indices and want to avoid doing anything destructive. What is the best way to create a column of unique integers for this case?

1 Answer 1

1

Found an answer:

SELECT *, json_array_elements(nested_json_as_text::json) as elements, row_number() over () as my_index FROM my_table
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.