I stumbled upon something that is behaving differently than what I would expect.
I have a column containing a json array, which I at times need to join with other data. I need to be able to get the index (or position) of the array element.
When only using table and json_to_array, I can compute the index using row_number() over ():
TABLE function output is unordered. We have a feature request open for a function like TABLE_EX that will have a serial number column in the output. No ETA for that. Maybe next year.
Your ROW_NUMBERS will get layered on to the result of the join, after the fact, in your example.
If you really need this, you could implement a Wasm TVF that includes a serial number column with the data from each array element.
Actually, some internal people at SingleStore solved this as part of a larger block of code by using this approach:
TABLE(our_function(json_array_input))
In “our_function” they used PSQL, not Wasm. They took the documents in the input json array, and put them in an enclosing document that also had a serial number property. Then the resulting docs were put back into an array and returned.
This was necessary because TABLE only outputs one column.
Their code is way too hairy to share here, because it is more general and solves more issues. But this approach can work.