decorator to execute remote stored procedure, specified as argument
Generally, the body of the decorated function should be empty. If it is not, the stored procedure will be executed first; the function body then.
Convert a value to a psycopg2 JSON object if necessary
execute_values_generator(cur, sql, argslist, template=None, page_size=100)¶
Execute a statement using SQL
VALUESwith a sequence of parameters. Rows returned by the query are returned through a generator. You need to consume the generator for the queries to be executed!
cur – the cursor to use to execute the query.
sql – the query to execute. It must contain a single
%splaceholder, which will be replaced by a VALUES list. Example:
"INSERT INTO mytable (id, f1, f2) VALUES %s".
argslist – sequence of sequences or dictionaries with the arguments to send to the query. The type and content must be consistent with template.
the snippet to merge to every item in argslist to compose the query.
If the argslist items are sequences it should contain positional placeholders (e.g.
"(%s, %s, %s)", or
"(%s, %s, 42)” if there are constants value…).
If the argslist items are mappings it should contain named placeholders (e.g.
"(%(id)s, %(f1)s, 42)").
If not specified, assume the arguments are sequence and use a simple positional template (i.e.
(%s, %s, ...)), with the number of placeholders sniffed by the first element in argslist.
page_size – maximum number of argslist items to include in every statement. If there are more items the function will execute more than one statement.
yield_from_cur – Whether to yield results from the cursor in this function directly.
After the execution of the function the cursor.rowcount property will not contain a total result.