jackc / jackc/pgx

Support copy protocol text format with CopyFrom

Open
#1,362 3 comments 5 reactions 0 assignees View on GitHub
enhancement v5
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

Unlike regular queries the copy protocol requires all values be formatted in binary or text. It does not allow some types formatted as text and some as binary.

`CopyFrom()` currently always uses the binary protocol. This requires all types to be registered and to support the binary format.

This means that enum and other string-like types cannot be used without registration even though they work with normal query functions. See #1338.

In addition, those who simply wish to pass strings into copy (apparently how `pq.CopyIn()` worked) without any type conversion are unable to do so. See #1346.

If `CopyFrom()` supported the text protocol both these issues would be resolved.

`CopyFrom()` could automatically fallback the text protocol as needed. This would be most convenient for the user and would entail no interface changes.

Another option is to allow the caller to determine the desired format. This would allow the caller to ensure the binary format is being used (i.e. ensure the fastest mode is being used) or get the feedback of an error message.

I lean toward the automatic fallback option.

Contributor guide

Open the contributing guide

Research direction

Start at the CopyFrom entry point and trace how the current binary copy protocol is selected and how type registration affects it. Read the context from issues #1338 and #1346, then compare the automatic-fallback and caller-selected-format proposals; the work is done when the chosen behavior supports text-format values without requiring registration and has corresponding coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.