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

Fix explicit casts #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix explicit casts #17

wants to merge 2 commits into from

Conversation

kim-anchorzero
Copy link

This fixes jawj#180. @dmitri-anchorzero this could be of use in the new json subquery stuff when using zapatos.param()

Copy link
Collaborator

@jcoveney-anchorzero jcoveney-anchorzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sunil got a little test suite working with an in memory database. may be worth adding a test that fails than succeeds for this? I admit to not knowing the rules for this sort of cast in postgresql very well..

@@ -347,7 +347,7 @@ export class SQLFragment<RunResult = pg.QueryResult['rows'], Constraint = never>

} else if (typeof expression.cast === 'string') {
result.values.push(expression.value);
result.text += `CAST(${placeholder} AS "${expression.cast}")`;
result.text += `CAST(${placeholder} AS ${expression.cast})`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow what removing the quotes fixes. Can you elucidate? Quickly checking in pgAdmin query tool seems like the quotes are indeed not needed, but also not harmful there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the quotes I was getting errors.. except when the value was "json." All other quoted type strings would fail.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't argue with empiricism!

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 this pull request may close these issues.

Cant cast parameter to native types
3 participants