1

In Clickhouse I have an array column. Can I output each value in the array and its corresponding index/position (+1) within?

So given ['c','b','a'] I would like to output

key        position
c          1
b          2
a          3

1 Answer 1

4
select a,i from 
     (select  ['c','b','a'] arr)
      array join arr as a, arrayEnumerate(arr) as i
┌─a─┬─i─┐
│ c │ 1 │
│ b │ 2 │
│ a │ 3 │
└───┴───┘



select  (arrayJoin(arrayZip(arr, arrayEnumerate(arr))) as x).1 a, x.2 i
from 
     (select  ['c','b','a'] arr)
┌─a─┬─i─┐
│ c │ 1 │
│ b │ 2 │
│ a │ 3 │
└───┴───┘     
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much Denis

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.