Closed notconfusing closed 4 years ago
What kind of param style are you using? Have you tried looking at the query which is created from jinjasql?
@notconfusing JinjaSQL works perfectly well with multiple usages of the same variable in a single query. It assigns a random postfix to the key generated for same named parameter. In your case, JinjaSQL would have created two keys - population_table and poulation_table_456 (with some random number).
Can you please share the following details to track this issue down?
j.prepare_query(templ, params_dict)
@devashishsharma2302 The version of jinjasql which replaces with an underscore has not yet been pushed to pypi. On version 0.1.6 it's currently using #
as a delimiter not _
.
Because of this jinjasql will fail when trying to execute in sqlalchemy using named parameters, as #
is not considered a valid character in sqlalchemy bind parameters.
I would guess that issue is happening here, since engine
looks sqlalchemy like. 🤔
@henryrizzi Version 0.1.7 with the change is pushed to PyPi now. Thank you for reporting! @notconfusing Can you upgrade JinjaSQL to version 0.1.7 and check if the issue still persists?
Closing this ticket as I believe the underlying issue has long been resolved.
Given the example query
If I call:
query, bind_params = j.prepare_query(templ, params_dict)
and thenengine.execute(query, bind_params)
I get the error that there aren't enoughbind_params
to substitute intoquery
. I believe this is because I've included the{{population_table}}
variable twice in the template.How could I go about fixing this? (It might be true that I should execute those queries separately, but it's also valid to have a case where there are several of the same substitution in one query).