Skip to content
Advertisement

JSONB sort aggregation

I found this query that suits my needs thanks to this answer here in order to sort fields of data in a JSON document.

(Fake, generated random data)

As we can see, this works with hardcoded data which doesn’t quite fit my needs. I can’t seem to figure out how to replace the JSON data with the jsonb column in my table.

My attempt below yields ‘data is not defined’

My suspicions are that a subquery is needed inside the FROM clause?

Here is a SQLFiddle of my issue to help describe the table and how the structure is defined: http://sqlfiddle.com/#!17/41102/92

Advertisement

Answer

You are almost there. You just need to bring in the original table, like so:

Updated DB Fiddle

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