Skip to content
masterclass Buddy

PostgreSQL · Command

COPY

COPY moves data between PostgreSQL tables or query results and files, programs, or the client connection. FROM imports rows; TO exports rows.

Last updated

Syntax

COPY table_name [ ( column_name [, ...] ) ] FROM { 'filename' | PROGRAM 'command' | STDIN } [ [ WITH ] ( option [, ...] ) ] [ WHERE condition ]
COPY { table_name [ ( column_name [, ...] ) ] | ( query ) } TO { 'filename' | PROGRAM 'command' | STDOUT } [ [ WITH ] ( option [, ...] ) ]

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • pg_stat_progress_copy
  • \copy
  • FORMAT
  • ON_ERROR
  • REJECT_LIMIT
  • PQputCopyData
  • PQgetCopyData
  • STDIN

Source: PostgreSQL: Documentation: 18: COPY. Checked 2026-11-03.