psycopg/psycopg2 — pull request #16 by mrmilosz (2014-05-25 04:04:57+00:00)
Title: cursor.callproc now also accepts dict for PostgreSQL 9+ "named notation"

Starting with PostgreSQL 9.0, functions can be called using "named parameters": https://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.0#Named_Parameter_Calls

This is especially useful for functions with a large number of arguments, as it allows you to refer to the arguments by name instead of having to remember their order. This small patch allows cursor.callproc to accept a Dict instead of a List to mirror PostgreSQL's feature. No previous functionality has been removed.

Like the name of the stored procedure itself, the names of the parameters are NOT sanitized. This means that, just as the programmer should not expose control of the name of the stored procedure to the end user, the programmer should not expose control of the parameter names either.

A macro was added to python.h for the python-version-agnostic conversion of text objects into C char arrays (specifically the procedure parameter names, which come from the Dict keys.)

The code compiles and runs correctly under Python 2.7 and Python 3. There were no existing test suites for callproc (that I could find) so I wasn't sure where to put test suites for this new functionality. I used the following code to test:

https://gist.github.com/mrmilosz/905a4492216052821c38

Any procedure returning a value and matching the prototype will work for the test.

Thank you for your time. I hope you can make this patch a part of the trunk as it introduces a feature I would very much like to use! Of course, if I made any silly mistakes you are free to fix them first. For what it's worth I tried to pay close attention to my new/borrowed references and Py_DECREFs, but I am new to the Python C API.