Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from psycopg2.extensions import adapt
- def get_query(query, params=None):
- """Returns the query which is supposed to be run in Postgres.
- :param query: String representation of the query
- :param params: Dict of parameters
- :return: String representation of the query when the parameters are filled out
- """
- actual_params = {k: adapt(v) for k, v in params.iteritems() if params}
- _query = query % actual_params
- return _query
- query_to_run = 'SELECT * FROM accounts WHERE id = %(id)s'
- params = {'id': '1'}
- print(get_query(query_to_run, params))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement