-
Notifications
You must be signed in to change notification settings - Fork 279
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
Error: cannot cast type boolean to jsonb #386
Comments
Maybe an issue with parameters types inference 🤔 On the meantime, maybe you can use await sql`SELECT ${sql.json(true)}::jsonb`; |
Yes, this is an erroneous type inference, for the boolean type of JS, the serelizer to the postgres boolean type is always used, but this is not correct for JSON
Unfortunately, it is not possible to use the |
Ok but your cast to |
The problem is that the |
@uasan oh shoot, that's actually not the only issue. Same goes for the other inferred types (Date, Buffer, Bigint) :-( I should have caught this for the v3 update and completely removed inferType ( Line 213 in 218a7d4
|
You, like many good developers, simply do not have enough tests for many cases, you need to think about how the community can help you write tests |
It was really an assumption on my part wrt. handling of values after supporting the PostgreSQL feedback, but I guess you can say I might have caught it if I had had a test case for these json situations. Hindsight is 20/20 ;) Currently a simple test case I have now is enabling this behaviour which prevents json from working out of the box:
So we can't really have both, but I think it would have been more correct to support the json case, and accept that input without explicit types just becomes strings? Eg this would have been better behavior:
But.. still initial thinking - might feel differently after sleeping on it :P |
I think the best behavior in cases of
|
@porsager Hi. Should we expect a fix soon? If yes, how long? P.S. I don't want to raise, but this is a pretty critical issue for us. Wish you happy coding. |
@AkeleyUA the issue is that we can't really change it without potentially breaking someone who relies on the implicit inference. It would require a new major, and I haven't thought through if that's the way to go yet. Could you maybe describe your specific issue / show an example query, and we can see if there's a way to work around it? |
Dynamic query builder that knows the column name and values, but does not know the type of the column sql`UPDATE table SET "${sql(name)}" = ${value}`
I'm pretty sure no one is relying on |
I think It's useful when calling functions that don't do the same implicit type casts as regular queries. I'm pretty sure someones setup will break if changing it, and the fact that it's an explicit functionality tested for, it would definitely require a major bump (but I don't mind if that's necessary). So if we make that change, it would be removing all implicit type inference from js types supplied in the Parse message and rely completely on the PostgreSQL I'll try to see if I can find any good reasons not to do it 😉 |
Inference data type for Postgres from the data type of JS, has sense only if the |
Yeah I'm very curious too I think it's not possible because the types specified from our end are supplied in the |
I mean at least not in an efficient way, that would require us to call |
Do not need to call |
Right, but we can't supply types to |
Send a one-time |
Here are links to my unfinished postgres client: One-time creation of Reusable type reuse in a |
It's not different from what Postgres.js does and you're still not able to tell the db about alternative types after the fact? |
You can pass alternative types to |
No you can only decide in bind if a parameter is text or binary encoded. That's not related to postgres types. |
Yes, of course, during the life of a |
Sorry - I thought you were proposing / exploring a way to allow setting input types when the db returned unknown in ParameterDescription. |
If db returned unknown in ParameterDescription - in this case type inference is appropriate or use text type, it's ok. |
Hello.
Version
postgres 3.2.4
.Result postgresql error:
The text was updated successfully, but these errors were encountered: