How to export a VIEW with COPY TO?

I would like to export data of a VIEW to a file. Is this possible with COPY TO?
So far I haven’t found a solution for this.

Hi @tenforward,

COPY TO currently doesn’t support views, unfortunately. There is an open feature request, please feel free to express your interest there as well: copy to support "view" · Issue #7930 · crate/crate · GitHub

A workaround would be to copy the view to a table and then use COPY TO on that table:

CREATE VIEW v1 AS SELECT 1;

CREATE TABLE doc.tmp AS
SELECT *
FROM v1;

COPY doc.tmp TO DIRECTORY 'file:///tmp/';
1 Like