-
Notifications
You must be signed in to change notification settings - Fork 61
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
Templating Identifers into SQL #21
Comments
Hmmm, neat idea. Let me think about how we could approach this. Any initial thoughts @nackjicholson? Thoughts on requiring another identifier, such as |
It would be neat to have a possibility to dynamically change the behavior of the query depending on supplied columns. The way I would do this is to use Jinja2 to process SQL and provide access to parameters. If dependencies or performance is an issue, use an operator or smth like this to specify normal or Jinja2 style of SQL. |
Using string templates or jinja to do this could be dangerous. psycopg2 has sql identities to handle this case correctly. |
@frafra I didn't mean to use Jinja2 for variable substitution in SQL. Contrary, I think variable substitution must be handled by the driver. But let's define what problem I would solve with Jinja2. Imagine you have to implement a query to update With help of Jinja2 (or another template) it would look like this:
Here I used aiosql as a variable containing a dict of fields/values passed. SQL arguments/fields left as is. Information about fields passed is used to select what fields should be updated. |
There is a project called Or maybe we can dive into I think that using |
Hmmm. I agree that it could be helpful in some cases, but ISTM that |
honza/anosql#45 and honza/anosql#47
Are both asking for support for Identifiers in order to template other values into the SQL, like table names. I've never had need for this, and actually wasn't aware of it as a feature in
psycopg2
, but it's worth some thought to see if it's something we can do in this project.One potential problem in the way of doing this is that the other driver libraries like
sqlite
orasyncpg
may not have safe features for doing this. I just really don't know since I've never had to do this kind of table name formatting.The text was updated successfully, but these errors were encountered: