Using WITH together with CREATE TEMPORARY TABLE AS SELECT ... in Postgres?
The WITH goes after the CREATE TABLE

CREATE TEMPORARY TABLE foo 
AS
WITH a AS (
SELECT 1 foo, 2 bar 
), b AS (
SELECT 4 bar, 5 baz
)
SELECT * from a JOIN b ON (a.bar=b.bar)


Note the above will result in "ERROR: column "bar" specified more than once" - but I assume you are using better (distinct) column names in the real query.