There's a proof-of-concept code in the git repo that works, but it's still very messy and only changes the portal code. It also doesn't handle snapshots correctly, but it's not yet clear what the code should look like (see NOTE near the bottom of this item). Not all regression tests for WITH are applicable because we don't need to support non-top-level CTEs, so they've been taken out from the git repo. Also a RECURSIVE query must not loop forever, so those tests are gone too. All remaining tests are passed now.

WITH t1 AS (DELETE FROM src RETURNING *),
t2 AS (INSERT INTO dest SELECT * FROM t1 RETURNING *)
SELECT * FROM t2

RECURSIVE query is fine as long as 1) it's SELECT-only and 2) it doesn't loop forever. WITH RETURNING cannot be contained in RECURSIVE. A wCTE can of course refer to the result of the recursive SELECT query with INSERT .. SELECT, UPDATE .. FROM or DELETE .. USING. :