pgbinary

package
v0.0.0-...-7a6daa5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pgbinary validates and normalizes PostgreSQL binary COPY streams before they are handed to DuckDB's postgres_scanner extension.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rewrite

func Rewrite(dst io.Writer, src io.Reader, schema Schema) (int64, error)

Rewrite validates src and writes a scanner-compatible PostgreSQL binary COPY stream to dst. NUMERIC values are coerced to their destination scale using round-half-away-from-zero, matching PostgreSQL's numeric typmod behavior.

func RewriteProtocolCompleted

func RewriteProtocolCompleted(dst io.Writer, src io.Reader, schema Schema) (int64, error)

RewriteProtocolCompleted validates a protocol-completed binary COPY stream and writes scanner-compatible file framing, including one canonical trailer when the protocol ended cleanly between tuples without one.

Types

type Column

type Column struct {
	Numeric *Numeric
	// contains filtered or unexported fields
}

Column describes scanner-sensitive properties of one binary COPY column. A nil Numeric means the field can be validated and copied byte-for-byte.

type Inspection

type Inspection struct {
	Rows         int64
	NeedsRewrite bool
}

Inspection reports whether a scanner-compatible rewrite is needed.

func Inspect

func Inspect(src io.Reader, schema Schema) (Inspection, error)

Inspect validates a complete PostgreSQL binary COPY stream without retaining it in memory. It reports whether NUMERIC scales or a header extension require a scanner-compatible rewrite.

func InspectProtocolCompleted

func InspectProtocolCompleted(src io.Reader, schema Schema) (Inspection, error)

InspectProtocolCompleted validates a PostgreSQL binary COPY stream after its surrounding protocol has explicitly confirmed successful completion. In that mode, EOF between complete tuples is equivalent to the canonical file trailer and requests a rewrite that adds the canonical trailer.

type Numeric

type Numeric struct {
	Precision int
	Scale     uint16
}

Numeric describes the destination DECIMAL typmod for a PostgreSQL NUMERIC field. PostgreSQL applies this typmod (including rounding) while loading a binary COPY stream; DuckDB's read_postgres_binary currently assumes the field's wire dscale already matches it, so we apply that coercion explicitly.

type Schema

type Schema struct {
	Columns []Column
}

Schema is the expected tuple layout for a binary COPY stream.

func SchemaFromDatabaseTypes

func SchemaFromDatabaseTypes(databaseTypeNames []string) (Schema, error)

SchemaFromDatabaseTypes builds the validation schema carried from the control plane's lossless column metadata. Non-numeric types need no payload transformation, but still contribute to the exact tuple width.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL