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

Empty PostgreSQL ARRAY should be printed with a cast #853

Open
tisonkun opened this issue Jan 2, 2025 · 3 comments · May be fixed by #854
Open

Empty PostgreSQL ARRAY should be printed with a cast #853

tisonkun opened this issue Jan 2, 2025 · 3 comments · May be fixed by #854

Comments

@tisonkun
Copy link
Contributor

tisonkun commented Jan 2, 2025

Otherwise, it will fail with "cannot determine type of empty array".

For example, an empty string vec will be converted to ARRAY [] but PG needs ARRAY[]::TEXT[] or things like that for understanding the type.

@tisonkun
Copy link
Contributor Author

tisonkun commented Jan 2, 2025

Or use {} as reported at graphile/crystal#406.

@tisonkun tisonkun linked a pull request Jan 2, 2025 that will close this issue
@tisonkun
Copy link
Contributor Author

tisonkun commented Jan 2, 2025

I provide a fix in #854, but found another issue that if we render a Vec<Uuid> to array, it would be like ARRAY[ '<uuid>' ] that would be inferred as TEXT[]. So we may instead render a cast for all array value, i.e., ARRAY ['<uuid>'] :: UUID[], and ditto to all array types.

@tisonkun
Copy link
Contributor Author

tisonkun commented Jan 2, 2025

ARRAY [''] :: UUID[]

This would failed on type mismatch like String may be TEXT or VARCHAR. Then I'd like to keep #854 while other types can be cast with SimpleExpr::cast_as.

For example:

// ids: Vec<Uuid>
let expr: SimpleExpr = request.ids.clone().into();
expr.cast_as(IdenStr("UUID[]"))

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

Successfully merging a pull request may close this issue.

1 participant