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

postgres error when inserting slice value #145

Open
ahsanulks opened this issue Feb 22, 2021 · 4 comments
Open

postgres error when inserting slice value #145

ahsanulks opened this issue Feb 22, 2021 · 4 comments

Comments

@ahsanulks
Copy link
Contributor

I have a struct with data
type Example struct { RelatedIDs []int }

when inserting on database. I have error with message sql: converting argument $8 type: unsupported type []int, a slice of int. But postgres is already support data type with array. I think it miss implementation on build the query if the data is slice on rel

@Fs02
Copy link
Member

Fs02 commented Feb 22, 2021

yes, you are correct, rel currently doesn't implicitly handle array types (if you think this will be useful, please feel free to open a pr 😄 ).

as an alternative, you can implement Scanner interface to a custom int type, or if you are using lib/pq as the driver, you can just use this type: https://github.com/lib/pq/blob/072e83d238c297c71cab11154695af301010031e/array.go#L501-L517

@ahsanulks
Copy link
Contributor Author

ok thanks that fix my problem

update on this https://github.com/go-rel/rel/blob/master/adapter/sql/builder.go#L338 function right? But It's ok to change the adapter function? because I think mysql and sqlite doesn't support for array value cmiiw.

@Fs02
Copy link
Member

Fs02 commented Feb 23, 2021

update on this https://github.com/go-rel/rel/blob/master/adapter/sql/builder.go#L338 function right? But It's ok to change the adapter function? because I think mysql and sqlite doesn't support for array value cmiiw.

yes correct, mysql and sqlite doesn't support it, so I think the update should only be specific for postgresql adapter, and I also would like to avoid importing driver package in adapter, to make it driver independent.

@ahsanulks
Copy link
Contributor Author

ok. I will try to make pr on this weekend about this

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