-
Notifications
You must be signed in to change notification settings - Fork 471
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
Where with parametrized INTERVAL #379
Comments
Assuming you are using postgres, I believe the quotes are the problem: |
That's correct, I'm using postgres. Without quotes, it's not a valid SQL statement:
|
It looks like postgres expects the number to be a string, so you may also need to e.g. |
Thanks but still even with days converted using
|
The quotes mean you are passing the literal string "? DAYS"; Squirrel converts the I believe what you need is: squirrel.Expr("expiry <= now()::timestamptz - INTERVAL ? DAYS", strconv.Itoa(days)), |
The example that you provided will generate the following SQL query:
In order for that to work with postgres: https://www.postgresql.org/docs/8.0/functions-datetime.html, the INTERVAL should use quotes
|
Ah sorry, I got bad information from Google. In that case I would expect something like this to work: squirrel.Expr("expiry <= now()::timestamptz - INTERVAL ?", fmt.Sprintf("%d DAYS", days)) |
Unfortunately, this would also fail:
|
Only way I've gotten this to work is by doing something such as the following
Where finalInterval is a number. The key part being the multiplier, unfortunately seems like a driver issue. |
Hi,
I'm having an issue with using where expr with parametrized INTERVAL.
Code:
I'm getting the following error:
Generated query and args:
Expected SQL:
Is this a bug? Is there any other way this can be achieved?
Thanks!
The text was updated successfully, but these errors were encountered: