Skip to content
Advertisement

Order and limit data based on JSONB array

I have such a PostgreSQL table

Now I would like to get all sorted val and have the limitation for each query (for pagination). For example 1st query

2nd query

Advertisement

Answer

You need to unnest the array, sort the result then apply offset and limit:

Instead of limit 5 you can also use the standard compliant fetch first 5 rows only

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