You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The messages should be sorted by createdAt, as specified in the public.test_messages function. (The correct order in the example above is messages counting down from 3 to 1, alternating between Bob and John each message).
Actual results
The messages are sorted somewhat randomly (in my case it was sorting by User.id).
Possible Solution
Quoting Benji on Discord:
My guess is that we're treating the function as a table, and then doing a left join to users at which point the order of values returned from the function is no longer guaranteed (Postgres can choose any order it wishes if it's not explicit; it just happens that it sticks to function order when you only query the function).
In that case, what we should do is select ... from my_func() with ordinality left join users ... order by ordinality or select ... from (select row_number() over (partition by 1), v from my_func() v) t left join users ... order by t.row_number or something like that.
The text was updated successfully, but these errors were encountered:
Summary
Original discussion on Discord https://discord.com/channels/489127045289476126/1293563114125787197
When querying a function that returns a pre-sorted
setof
, the values returned are non-deterministic if relational data is also queried.Steps to reproduce
A "minimal" database structure and sample data:
And this GraphQL query (assuming you are connected to the database as a
super_test
role):Expected results
The messages should be sorted by
createdAt
, as specified in thepublic.test_messages
function. (The correct order in the example above is messages counting down from 3 to 1, alternating between Bob and John each message).Actual results
The messages are sorted somewhat randomly (in my case it was sorting by
User.id
).Possible Solution
Quoting Benji on Discord:
The text was updated successfully, but these errors were encountered: