Skip to content

generateCopyData

generateCopyData(rows, columns, columnTypes?): string

Defined in: packages/client/src/sync/copy.ts:234

Serialize a list of row objects into the body of a COPY ... FROM request in TEXT format. Columns are emitted in the given order, fields are tab separated, and rows are newline separated.

columnTypes optionally maps a column name to its Postgres udt_name; pass it so json/jsonb columns serialize correctly.

PUBLIC (re-exported from the package root) for an app-owned, pgxsinkit-unmanaged table. Two contracts bind the caller:

  • columns IS the column list of the COPY statement. The fields are emitted in exactly this order, so the same array must be named — in the same order — in the COPY <table> (...) that ingests the bytes. buildCopyFromBlobStatement renders both from one array so they cannot drift.
  • columnTypes keys are DB column names, values are Postgres udt_names (text, int4, jsonb, timestamptz, _text for text[], …). Only the json ones (json/jsonb/_json/_jsonb) change behaviour — everything else dispatches on the value’s runtime type — but passing the full map is harmless. A json/jsonb value MUST be the parsed value, per serializeCopyValue.

readonly Record<string, unknown>[]

readonly string[]

Readonly<Record<string, string | undefined>>

string