Lurker News

Comments (323) 88 threads

Show all comments

Showing thread 17 of 88

nknealk2 replies#
Can someone from EdgeDB explain why the SQL isn't as simple as what I have below? What am I missing? Why is that cross join lateral necessary:

  SELECT
      title,
      ARRAY_SLICE(ARRAY_AGG(movie_actors.name WITHIN GROUP (order by movie_actors.credits_order asc)),0,5)
      avg(movie_reviews.score)
  FROM movie
  JOIN movie_actors on (movie.id = movie_actors.movie_id)
  JOIN person on (movie_Actors.person_id = person.id)
  JOIN movie_reviews on (movie.id = movie_reviews.id)
  WHERE person.name like '%Zendaya%'
  group by title
RedCrowbar2 replies#
Because that only gives you actor names, not records, and also because arrays aren't a universal SQL feature.
eatonphil1 reply#
EdgeDB is already postgres specific though.
RedCrowbar1 reply#
EdgeDB currently is. Graph-relational and EdgeQL are not.

Continue this thread — 1 reply

nicoburns1 reply#
You can JSON_AGG to get whole records.
RedCrowbar#
Unfortunately, JSON aggregation destroys type information, so you can't reason about that your SQL query actually returns anymore.
RedCrowbar#
Also, this query is wrong because we want movies where Zendaya played, but _also_ other actors in order, possibly without Zendaya, so you really need to do the actors join twice.