sripathikrishnan / jinjasql

Template Language for SQL with Automatic Bind Parameter Extraction
MIT License
820 stars 90 forks source link

[Feature request] Single function with outputting the full query with parameters #46

Closed kishaningithub closed 2 years ago

kishaningithub commented 2 years ago

Usecase

Using python i am writing an aws lambda which interacts with redshift data api especially the BatchExecuteStatement operation. If you observe this api takes in list of SQL queries without any params.. meaning that the query should also have parameters within it as a single string

sripathikrishnan commented 2 years ago

I don't think this makes sense in JinjaSQL right now. Different databases have different escape functions, and at this point - I am not sure if we should complicate JinjaSQL.

You can achieve this outside of JinjaSQL fairly easily. For example, if you are using psycopg library for postgres/redshift, it exposes a mogrify function. You take the output of prepare_query and pass it to mogrify, and you should get the full query.

I presume other libraries also have a similar function.

kishaningithub commented 2 years ago

I agree mapping the params to appropriate sql column types is a database dependent operation and would be too much for this library.

Closing this issue..

Also, not all libs and apis(looking at redshiftdata api) provide a mogrify function :-(