I have a data set that has an array property. Example when I select * from c
:
[
{
"id": "1",
"props": []
},
{
"id": "2",
"props": ["a"]
},
{
"id": "3",
"props": ["b"]
}
]
I want to run this query to order by the props column:
select * from c order by c.props
BUT it returns 0 records because the first array item is empty (if I drop the order by it works fine and returns the three records). I can do this to attempt to work around it:
select c.* as item, props = [] ? '' : props[0] as orderCol from c
Returns all three items (has no order by) but when I try to apply the order by like this:
select c.* as item, props = [] ? '' : props[0] as orderCol from c order by c.orderCol
It returns 0 records. What am I doing wrong? (I dont want a where clause to filter the empty props records). Basically, I can't order by my custom selected field "orderCol" when I want to.
NOTE: using order by c.id
works fine!
Thanks for any pointers in advance!