-
Notifications
You must be signed in to change notification settings - Fork 871
Running :copyfrom with a uuid causes ERROR: incorrect binary data format (SQLSTATE 22P03) with PGX #1507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Updating my code from: func (r iteratorForBulkInsertAdResults) Values() ([]interface{}, error) {
return []interface{}{
r.rows[0].Query,
r.rows[0].Location,
r.rows[0].LocationType,
r.rows[0].IsTop,
r.rows[0].Position,
r.rows[0].NumberOfTopResults,
r.rows[0].TotalNumberOfAds,
r.rows[0].Headline,
r.rows[0].Description,
r.rows[0].Url,
r.rows[0].AdCheckParentID,
}, nil
} to: func (r iteratorForBulkInsertAdResults) Values() ([]interface{}, error) {
asBinary, err := r.rows[0].AdCheckParentID.MarshalBinary()
if err != nil{
return nil, err
}
return []interface{}{
r.rows[0].Query,
r.rows[0].Location,
r.rows[0].LocationType,
r.rows[0].IsTop,
r.rows[0].Position,
r.rows[0].NumberOfTopResults,
r.rows[0].TotalNumberOfAds,
r.rows[0].Headline,
r.rows[0].Description,
r.rows[0].Url,
asBinary,
}, nil
} Worked :) |
I have encountered this problem too. I do not think this is a bug. But it is nice to write some documents to warn people who want to The reason for this problem is neither A quick solution is to add For example version: "1"
project:
id: ""
packages:
- path: "***"
name: "document"
engine: "postgresql"
schema: "***"
sql_package: "pgx/v4"
queries: "***"
overrides:
- go_type: "github.com/jackc/pgtype.UUID"
db_type: "uuid"
- go_type: "github.com/jackc/pgtype.UUID"
db_type: "uuid"
nullable: true |
I'm running into this too with the following settings:
I noticed an extra detail here which is that the failure only happens for me when a This is consistent with the OP's case it seems since Is there a better workaround here than overriding with the pgtype as suggested? We have far too many locations where we've been using Google's UUID to make this an easy swap by doing so and that just feels way too heavy-handed as a workaround. We can't afford to wait for pgx v5 to settle either (not to mention the cost of switching over to that). Is the next best option to change the copyfrom query to a transacted loop of single inserts? I spent some time trying to get a custom type to work but it seemed to suffer the same problem which makes sense since it still doesn't really affect how the copyfrom code is being generated or used. |
I believe this has been fixed in |
@kyleconroy , got some time to work on the upgrade today and this does appear to be fixed now in v5, thank you very much sir! For anyone else migrating from v4, these were super helpful resources: |
Version
1.12.0
What happened?
A bug happened!
Relevant log output
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/2d26c7887908446358ff23c10defa67e2a2d3a7c4f34e2b1a0e686560420659e
What operating system are you using?
Windows
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: