Fork me on GitHub
#honeysql
<
2020-08-08
>
viesti19:08:12

Hmm, is there a way to use CTE and UNION together, so that I could refer to the CTEs from the UNION clauses?

viesti19:08:06

something like this in sql:

WITH cte AS (
  SELECT
    *
  FROM
    shared
)
SELECT
  cte.id,
  f.x
FROM
  cte
  LEFT JOIN foo f ON f.id = c.id
UNION
SELECT
  cte.id,
  b.x
FROM
  cte
  LEFT JOIN bar b ON b.id = c.id;

viesti20:08:20

ah, hmm, just using a map {:with ... :union [...]} and referring to the cte's in the :union by name seems to work

viesti20:08:42

the dsl tripped me off a bit