[DB-SIG] Some obscurity with paramstyle

Michael Bayer mike_mp at zzzcomputing.com
Sat Jul 16 22:27:18 CEST 2011

On Jul 16, 2011, at 3:20 PM, Christoph Zwerschke wrote:

> At the PyGreSQL mailing list we're currently wondering whether the 'format' and 'pyformat' paramstyles allow specifying parameters with types other than '%s' - e.g. can I specify my parameter as '%.2f' or '%(name).2f' if I want to round floats to 2 digits?
> PEP 249 has only '%s' in the example, but does not exclude other types,
> does this mean these are allowed?
> Also, should we define a new paramstyle for the advanced string formatting syntax available since Py 2.6?

Not all backends that support "format" or "pyformat" would be able to allow such behavior - often the client API of the database in use is passed, from the DBAPI, the SQL statement with placeholders and the parameters separately - no "string formatting" takes place.    A DBAPI that advertises "format" or "pyformat" then may or may not be able to handle the extended syntax.

IMHO I would prefer to see the DBAPI have exactly two paramstyles, named and qmark, and have all DBAPIs support both consistently.    The (py)format styles continuously introduce the mixing of Python's string formatting behavior with the presentation of bound parameters, which are two completely different things.

More information about the DB-SIG mailing list