Question

Is there anyway to do this? I'm trying to do something like this:

SELECT x
FROM table
EXCEPT
WITH RECURSIVE ...();
Was it helpful?

Solution

The WITH goes first in a query. You can use this:

WITH RECURSIVE ct AS (...)
SELECT x
FROM table
EXCEPT
SELECT y
FROM ct ;

For the record, CTEs can be (in standard SQL) inside subqueries but not many DBMS have implemented this syntax:

SELECT x
FROM table
EXCEPT
SELECT y
FROM 
  ( WITH RECURSIVE ct AS (...)
    SELECT y
    FROM ct 
  ) AS c ;

or this simpler one:

SELECT x
FROM table
EXCEPT
( WITH RECURSIVE ct AS (...)
  SELECT y
  FROM ct 
) ;
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top