COPY TO

COPY TO sends rows using the Postgres COPY protocol.

Syntax

COPY ( query ) TO STDOUT WITH ( field val , )
Field Use
query The SELECT or SUBSCRIBE query to send
field The name of the option you want to set.
val The value for the option.

WITH options

Name Value type Default value Description
FORMAT TEXT,BINARY TEXT Sets the output formatting method.

Example

Copying a view

COPY (SELECT * FROM some_view) TO STDOUT;

Subscribing to a view with binary output

COPY (SUBSCRIBE some_view) TO STDOUT WITH (FORMAT binary);

Privileges

The privileges required to execute this statement are:

  • USAGE privileges on the schemas that all relations and types in the query are contained in.
  • SELECT privileges on all relations in the query.
    • NOTE: if any item is a view, then the view owner must also have the necessary privileges to execute the view definition. Even if the view owner is a superuser, they still must explicitly be granted the necessary privileges.
  • USAGE privileges on all types used in the query.
  • USAGE privileges on the active cluster.
Back to top ↑