-
Notifications
You must be signed in to change notification settings - Fork 749
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
Executing query that takes an array of a custom enum type with pgx/v4 fails #1256
Comments
A workaround for this issue is to convert the column being compared into -- name: ListWidgets :many
SELECT * FROM widgets
WHERE "type"::text = ANY(@type::text[])
AND user_id = @user_id; |
I also hit this, and am motivated to fix it. Another workaround is to use It seems like the easiest fix may be to extract sqlc could copy the array code in when it detects it is needed. (Or it could try to emit only the parts it really needs, but that's probably unnecessary.) Then sqlc could use that code unilaterally, including in pq mode. If that approach sounds good, I'd be happy to send a PR, but I'd need a few pointers. I found the spot where |
Scratch that, it doesn't quite compile cleanly out of the box. But this does: https://github.com/josharian/pqarray. |
Another workaround is to use a column go_type override with an appropriate type from github.com/josharian/pqarray, and then write your own conversion helpers. Ugly, but still retains a bit of type safety. |
It's enough to implement a Example type Topic string
type Topics []Topic
const (
Family Topic = "family"
Hiking Topic = "hiking"
Bicycle Topic = "bicycle"
)
func (t *Topics) DecodeText(ci *pgtype.ConnInfo, src []byte) error {
var dec pgtype.TextArray
if err := dec.DecodeText(ci, src); err != nil {
return err
}
for _, el := range dec.Elements {
*t = append(*t, Topic(el.String))
}
return nil
}
func (t Topics) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
var enc pgtype.TextArray
if err := enc.Set(t); err != nil {
return nil, err
}
return enc.EncodeText(ci, buf)
} |
I encountered the same problem, has this been fixed? Sql Queries
Configuration
Database schema
What happened?
|
Having similar issue when using insert with :copyfrom that inserts into enum field: |
Custom enum arrays work in pgx/v5 as long as you register the custom enum array type: #2510 (comment) |
Version
Other
What happened?
Executing query that takes an array of a custom enum type with pgx/v4 fails with:
Version: tested both with v1.8.0 and the latest main (6ee39cb)
Relevant log output
No response
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/4109299ab81a98ca6e06d6389d5a50aed1b8ffa8a4abfe9b761110f885afd3d6
What operating system are you using?
macOS
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: