Skip to content
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

comparing uncomparable type pgtype.VarcharArray #217

Open
bweston92 opened this issue Jun 10, 2024 · 3 comments
Open

comparing uncomparable type pgtype.VarcharArray #217

bweston92 opened this issue Jun 10, 2024 · 3 comments

Comments

@bweston92
Copy link

To Reproduce

Use a Postgres type varchar[]

Create a query that queries it:

select mytype from mytype;

You'll see something like this in the generated code

// ...

type MyType struct {
	ID                *int32              `json:"id"`
	RemoteIdentifiers pgtype.VarcharArray `json:"remote_identifiers"`
}

// ...
func (tr *typeResolver) newMyType() pgtype.ValueTranscoder {
	return tr.newCompositeValue(
		"mytype",
		compositeField{name: "id", typeName: "int4", defaultVal: &pgtype.Int4{}},
// ...
		compositeField{name: "remote_identifiers", typeName: "_varchar", defaultVal: &pgtype.VarcharArray{}},
// ...
	)
}

Expected behavior

res, err := queries.FindMyType(ctx, 1)
// ...
var ids []string
_ = res.RemoteIdentifiers.AssignTo(&ids)
fmt.Printf("%+v", ids)
// to output a slice of string

Actual behavior

panic: runtime error: comparing uncomparable type pgtype.VarcharArray

goroutine 1 [running]:
github.com/jackc/pgtype.(*VarcharArray).Set(0xc0004e0038, {0xd200a0, 0xc0003f0180})
        external/com_github_jackc_pgtype/varchar_array.go:29 +0x114
github.com/jackc/pgtype.assignToOrSet({0xeaffc0, 0xc0003f0140}, {0xd2b740, 0xc0004e0038})
        external/com_github_jackc_pgtype/composite_type.go:171 +0xa2
github.com/jackc/pgtype.CompositeType.assignToPtrStruct({0x2, {0xd8047e, 0x6}, {0xc00005c200, 0x5, 0x5}, {0xc00051e410, 0x5, 0x5}}, {0xbf5c80, ...})
        external/com_github_jackc_pgtype/composite_type.go:212 +0x3d7
github.com/jackc/pgtype.CompositeType.AssignTo({0x2, {0xd8047e, 0x6}, {0xc00005c200, 0x5, 0x5}, {0xc00051e410, 0x5, 0x5}}, {0xbf5c80, ...})
        external/com_github_jackc_pgtype/composite_type.go:150 +0x1fb
@bweston92
Copy link
Author

Error goes away and runs fine if I remove these lines

pgtype/varchar_array.go

Lines 27 to 32 in a4d4bbf

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

@jackc
Copy link
Owner

jackc commented Jun 10, 2024

There's nothing that someone else can try to run here.

You'll see something like this in the generated code

What do you mean generated code? pgtype doesn't have any code that looks like that.


Also, I'd really suggest using pgx v5 instead of v4.

@bweston92
Copy link
Author

What do you mean generated code? pgtype doesn't have any code that looks like that.

Sorry I originally wrote this in the context of pgx until I realised the error was in this package.

I will try to get a failing test today if I can reproduce easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants