COPY formats
On this page
Reading and writing your own format through COPY … FROM / TO.
interface CopyFromFunctionConfig
Section titled “interface CopyFromFunctionConfig”export interface CopyFromFunctionConfig<TArgs = Record<string, unknown>>Fields
namestringHandler name (the function’s registered name;
Meta.name).formatstringSQL
FORMATidentifier users type, e.g.COPY t FROM 'x' (FORMAT myfmt).read(params: CopyFromReadParams<TArgs>) => void | Promise<void>Parse
pathand emit Arrow batches matchingexpectedSchema.descriptionstringoptionalFunction description (intrinsic documentation;
Meta.description).commentstring | nulloptionalOptional free-text comment surfaced by
vgi_copy_formats().directionstringoptionalReserved for a future
COPY ... TO; only"from"is supported today.optionsRecord<string, CopyFromOption>optionalCOPY options, keyed by option name. The
file_pathis NOT an option.categoriesstring[]optionaltagsRecord<string, string>optionalexamplesFunctionExample[]optionalrequiredSettingsstring[]optionalrequiredSecretsstring[]optionalonSecrets(params: { options: TArgs; path: string; bindCall: BindRequest; }) => CopySecretLookup[] | voidoptionalOptional secret-bind hook: forward CREATE SECRET credentials for secret-backed cloud sources (S3/GCS/HTTP/…). Called during bind (only on the first pass); return the secrets to resolve — typically scoped by the source
path. The framework’s two-phase secret bind resolves each lookup from the caller’s SecretManager and surfaces the resolved values onprocessParams.secretsatreadtime. Mirrors vgi-python’sCopyFromFunction.on_secrets.
interface CopyFromOption
Section titled “interface CopyFromOption”export interface CopyFromOptionDescription
Declaration of a single COPY option (a named function argument).
Fields
typeVgiDataTypeArrow type of the option value (e.g.
utf8(),int64()).docstringoptionalPer-option description, surfaced by
vgi_copy_formats().defaultunknownoptionalDefault value. When omitted the option is REQUIRED — the worker throws a clear error at COPY bind if the user does not supply it. Mirrors vgi-python’s
Arg(..., default=...)(no default => required).choicesunknown[]optionalOptional allowed value set, validated worker-side at bind. Mirrors vgi-python’s
Arg(..., choices=[...]).
interface CopyFromReadParams
Section titled “interface CopyFromReadParams”export interface CopyFromReadParams<TArgs = Record<string, unknown>>Fields
pathstringSource path from the
COPY ... FROM 'path'statement.optionsTArgsParsed COPY options (defaults applied).
expectedSchemaVgiSchemaThe COPY target’s schema. Every emitted batch must have this exact schema (names + types, in order) — DuckDB inserts no cast before the INSERT.
processParamsTableProcessParams<TArgs>Full process parameters (settings, secrets, storage).
outOutputCollectorCollector to emit batches / log.
finish()is called for you.
interface CopyToCloseParams
Section titled “interface CopyToCloseParams”export interface CopyToCloseParams<TArgs = Record<string, unknown>>Description
Parameters for the terminal close hook.
Fields
optionsTArgsParsed COPY options (defaults applied).
filePathstringDestination path from the
COPY ... TO 'path'statement.paramsTableBufferingParams<TArgs>Full buffering parameters (settings, secrets, storage, executionId).
interface CopyToFunctionConfig
Section titled “interface CopyToFunctionConfig”export interface CopyToFunctionConfig<TArgs = Record<string, unknown>>Fields
namestringHandler name (the function’s registered name;
Meta.name).formatstringSQL
FORMATidentifier users type, e.g.COPY t TO 'x' (FORMAT myfmt).write(params: CopyToWriteParams<TArgs>) => void | Promise<void>Persist one input
batchto a shard (called per sink batch).close(params: CopyToCloseParams<TArgs>) => number | void | Promise<number | void>Write the destination and close it, once (called on the coordinator). Read the shards persisted by
writeand perform the terminal write. Called even for empty input. Return the row count (informational).descriptionstringoptionalFunction description (intrinsic documentation;
Meta.description).commentstring | nulloptionalOptional free-text comment surfaced by
vgi_copy_formats().directionstringoptionalCOPY direction; only
"to"is supported here.orderedbooleanoptionalWhen true, the writer requires rows in source order — discovery advertises
ordered=trueand the extension uses a single-threaded sink (REGULAR_COPY_TO_FILE) so one worker receives every batch in source order. Mirrors vgi-python’sMeta.sink_order_dependent.optionsRecord<string, CopyToOption>optionalCOPY options, keyed by option name. The
file_pathis NOT an option.categoriesstring[]optionaltagsRecord<string, string>optionalexamplesFunctionExample[]optionalrequiredSettingsstring[]optionalrequiredSecretsstring[]optionalonSecrets(params: { options: TArgs; filePath: string; bindCall: BindRequest; }) => CopySecretLookup[] | voidoptionalOptional secret-bind hook: forward CREATE SECRET credentials for secret-backed cloud writes (S3/GCS/HTTP/…). Called during bind (only on the first pass); return the secrets to resolve — typically scoped by the destination
filePath. The framework’s two-phase secret bind resolves each lookup from the caller’s SecretManager and surfaces the resolved values onparams.secretsatwrite/closetime. Mirrors vgi-python’sCopyToFunction.on_secrets.
interface CopyToOption
Section titled “interface CopyToOption”export interface CopyToOptionDescription
Declaration of a single COPY option (a named function argument).
Fields
typeVgiDataTypeArrow type of the option value (e.g.
utf8(),int64()).docstringoptionalPer-option description, surfaced by
vgi_copy_formats().defaultunknownoptionalDefault value. When omitted the option is REQUIRED — the worker throws a clear error at COPY bind if the user does not supply it. Mirrors vgi-python’s
Arg(..., default=...)(no default => required).choicesunknown[]optionalOptional allowed value set, validated worker-side at bind. Mirrors vgi-python’s
Arg(..., choices=[...]).genumberoptionalOptional inclusive lower bound for numeric options, validated worker-side at bind. Mirrors vgi-python’s
Arg(..., ge=...).lenumberoptionalOptional inclusive upper bound for numeric options, validated worker-side at bind. Mirrors vgi-python’s
Arg(..., le=...).
interface CopyToWriteParams
Section titled “interface CopyToWriteParams”export interface CopyToWriteParams<TArgs = Record<string, unknown>>Description
Parameters for the per-batch write hook.
Fields
batchVgiBatchOne input batch from the COPY source.
optionsTArgsParsed COPY options (defaults applied).
filePathstringDestination path from the
COPY ... TO 'path'statement.paramsTableBufferingParams<TArgs>Full buffering parameters (settings, secrets, storage, executionId).
function defineCopyFromFunction
Section titled “function defineCopyFromFunction”export function defineCopyFromFunction<TArgs = Record<string, unknown>>(config: CopyFromFunctionConfig<TArgs>,): VgiFunctionDescription
Define a custom COPY ... FROM format reader, returned as a VgiFunction
(kind "table") carrying the copyFromFormat metadata marker. Register it in
the catalog’s function list like any table function; the catalog’s
copyFromFormats() introspection picks it up and advertises the format.
function defineCopyToFunction
Section titled “function defineCopyToFunction”export function defineCopyToFunction<TArgs = Record<string, unknown>>(config: CopyToFunctionConfig<TArgs>,): TableBufferingVgiFunctionDescription
Define a custom COPY ... TO format writer, returned as a
TableBufferingVgiFunction (kind "table_buffering") carrying the
copyToFormat metadata marker. Register it in the catalog’s function list
like any function; the catalog’s copyFromFormats() introspection picks it
up and advertises the format (direction "to"). The worker’s
table_buffering_process / table_buffering_combine RPCs drive write/close.