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?
Not really. The DB-API 2.0 allows for a certain number of binding parameter formats, but you shouldn't really invent more. For the next version, we're likely going to reduce the number of allowed formats to just two (%s and ?, IIRC), since having lots of different formats has resulted in much confusion. > Also, should we define a new paramstyle for the advanced string > formatting syntax available since Py 2.6? No. See above. The problem with %s or any other format that resembles a Python string formatting character is that people (rightly) expect the full functionality of those to be available, which is not the case. There's a significant difference between string formatting characters and binding parameter characters: the latter just let the database module know where a certain parameter value should be added, but don't literally include the parameters in the SQL string, nor define how the parameters are passed to the database. Binding parameters just define an association between the SQL and the parameter list, nothing more. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 18 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig