Skip to content

Instantly share code, notes, and snippets.

@msullivan
Last active July 14, 2021 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msullivan/ecacbf65e8da0142e9710e9b429a8a9c to your computer and use it in GitHub Desktop.
Save msullivan/ecacbf65e8da0142e9710e9b429a8a9c to your computer and use it in GitHub Desktop.
simulate a FULL OUTER JOIN in edgeql
# Do a FULL OUTER JOIN on User.name[0] = Card.name[0]
# (the seed computable is to demonstrate that it works with computed data)
WITH
L := User { seed := random() },
R := Card,
joined := DISTINCT {
(FOR l IN {L} UNION ([l.id], [(SELECT R FILTER l.name[0] = R.name[0]).id] ?? <array<uuid>>[])),
(FOR r IN {R} UNION (([(SELECT L FILTER L.name[0] = r.name[0]).id] ?? <array<uuid>>[]), [r.id])),
},
FOR row in {joined} UNION (
{
l := (SELECT L { name, seed } FILTER .id = array_unpack(row.0) LIMIT 1),
r := (SELECT R { name, cost, element } FILTER .id = array_unpack(row.1) LIMIT 1),
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment