Home United States USA — software Error in PostgreSQL: Argument of WHERE Must Not Return a Set Error...

Error in PostgreSQL: Argument of WHERE Must Not Return a Set Error in PostgreSQL: Argument of WHERE Must Not Return a Set

283
0
SHARE

A query that I initially wrote didn’t work since part of it returned a set of boolean values. Instead, we have to use a LATERAL subquery to achieve our goal.
In my last post, I showed how to load and query data from the Strava API in PostgreSQL, and after executing some simple queries, my next task was to query more complex part of the JSON structure.
Strava allows users to create segments, which are edited portions of road or trail where athletes can compete for time.
I wanted to write a query to find all the times that I’ d run a particular segment. For example, the Akerman Road segment covers a road running North to South in Kennington/Stockwell in South London.
This segment has the ID ‘6818475’ , so we’ ll need to look inside segment_efforts and then compare the value segment.id against this ID.
I initially wrote this query to try to find the times I’ d run this segment:
This doesn’ t work since jsonb_array_elements returns a set of boolean values, as Craig Ringer points out on Stack Overflow .
Instead, we can use a LATERAL subquery to achieve our goal:
Perfect!

Continue reading...