Skip to main content

Module copy

Module copy 

Source
Expand description

v7.22 (mailrs round-13 / T2) — shared COPY text-format helpers.

PG’s COPY is not an engine statement in SPG: both consumers lower it to per-row INSERTs. The wire path (spg-server pgwire) has done this since v7.15 for COPY … FROM stdin CopyData frames; the embed path (Database::execute_script / spg import) gained it in v7.22 because default-format pg_dump emits COPY blocks, and the zero-change import promise covers the default format, not just --column-inserts.

This module is the single home for the pure pieces: text-row decoding (tab-separated, \N nulls, backslash escapes) and INSERT synthesis. The wire path delegates here; wire-specific concerns (CopyData framing, SKIP/ON_ERROR/JSON options) stay in pgwire.

Structs§

CopyFromSpec
The head of an embed-path COPY … FROM stdin; statement.

Functions§

build_copy_insert
Build INSERT INTO <table> [(cols)] VALUES (…) from a decoded row. Numeric-looking and boolean cells go in bare so the engine sees typed literals; everything else is single-quoted with SQL escaping.
decode_copy_text_row
Decode one COPY text-format data row: tab-separated cells, \N = NULL, C-style backslash escapes.
parse_copy_from_stdin_head
Parse the head of a COPY <table> [(cols)] FROM stdin statement (text format). Returns None when the statement is not that shape — including COPY … TO stdout and file endpoints. A trailing WITH (…) options tail is accepted and ignored except that a non-text FORMAT makes this return None (the embed path only lowers the text format; callers surface a clear error).