WITH aux_results AS (
SELECT id
FROM vendors
)
SELECT c.id
FROM customers AS c
WHERE c.vendor IN (SELECT * FROM aux_results);
Here is a naive and simple example of a CTE. The auxiliary statement uses SELECT to retrieve ids. To filter on them I have to use SELECT or an exception is thrown.
Why is this, Why is it a different pattern than using a subquery to make the same overall query?
See:
https://www.postgresql.org/docs/current/functions-subquery.html#FUNCTIONS-SUBQUERY-IN
It appears that the object returned by a subquery is different than the object returned by the CTE auxiliary statement. The way you must query is different, therefore the outer interface is different, yet they both could be considered transient tables.
As an aside, is there any performance hit? (doubt it) Should I just use a subquery? (doubt it)