Avoiding bindparams sometimes ? #11502
Unanswered
AbdealiLoKo
asked this question in
Usage Questions
Replies: 1 comment 2 replies
-
Hi, Both approaches work, but you need to look at the bindparam signature. You are passing the value as the name. Note that im this case parentheses work equally well: |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, i have a query which is pretty large.
And uses a lot of python variables and constants.
So many that sometimes older versions of sqlite complain with too many arguments to bind.
As per the sqlite documentation - Item 9 in limits (link):
In one part of this query, I have something like
extract("day", dt1 - dt2) * 24 * 60 * 60
And on checking with
echo
, I realized that this gets created with 5 bindparams.dt1
,dt2
,24
,60
,60
I'm trying to understand if there is a way for me to tell sqlalchemy that the 24, 60, 60 values are all constants.
Something like:
Where
bindnow
is used to tell sqlalchemy to immediately bind the value and not provide it as a parameter later on.Other approaches I've tried:
Approach 1: Precalculate the python parts of my expression
This should reduce the number of params to 3:
dt1
, dt2,
unit`Approach 2: Dedupe bindparams manually.
For example I can use the
bindparam()
function to create a param for 60 and reuse it twice as I learnt here:But obviously the Approach-1 would be better nad more intuitive.
Beta Was this translation helpful? Give feedback.
All reactions