In a WITH RECURSIVE query, is it possible to to use COPY TO in the same way INSERT INTO?
I'm trying to write a file from a recursive query without having to save it to a table first.
In a WITH RECURSIVE query, is it possible to to use COPY TO in the same way INSERT INTO?
I'm trying to write a file from a recursive query without having to save it to a table first.
sure why not, eg:
t=# copy ( WITH RECURSIVE t(n) AS (
VALUES (1)
UNION ALL
SELECT n+1 FROM t WHERE n < 100
)
SELECT sum(n) FROM t) to '/tmp/rc';
COPY 1
Time: 5.161 ms
t=# \! cat /tmp/rc
5050
COPY inside the CTE. But if not, this is a decent attempt to answer a very vague question.