Skip to content

Need help understanding CopyFrom into simple enum columns #1519

Answered by jackc
gurunandan-bhat asked this question in Q&A
Discussion options

You must be logged in to vote

There are two formats to encode values to send to PostgreSQL, text and binary. Normal queries can mix and match the format of parameters. The copy protocol requires all data be in the same format. The reason your enums work for normal queries is it can fall back to the text format. However, pgx's CopyFrom exclusively uses the binary format. That is why your enum fails there.

You have the right idea with LoadType and RegisterType, however, you are running it in the wrong place. It should be run in a AfterConnect hook (https://pkg.go.dev/github.com/jackc/pgx/v5@v5.3.0/pgxpool#Config).

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by gurunandan-bhat
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants