Skip to content
Advertisement

How do I check if an array is sorted with SQL?

I have the following table

and I want to output the arrays in the table which are sorted in ascending order. An output would be

I tried some stuff with array_agg and an order by inside the array_agg but that did not work. How would I go about getting the desired output?

Advertisement

Answer

You can install the intarray extension, then you can do:

If you don’t want to install the extension, you can create your own sort function:

Online example

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement