[DB-SIG] pyformat Parameter Style

Andy Todd andy47 at halfcooked.com
Sun May 11 21:33:43 EDT 2003

M.-A. Lemburg wrote:
> Chris Cogdon wrote:
>> On Saturday, May 10, 2003, at 10:23 US/Pacific, Andy Todd wrote:
>>> Is there a definitive specification of the pyformat parameter style 
>>> anywhere?
>>> The usual sources come up dry. It is mentioned in the DB-API 
>>> specification (http://www.python.org/peps/pep-0249.html) but not 
>>> defined.
>>> It seems from observation that one should simply put '%(<parameter 
>>> name>)s' in the query string and then pass a mapping with a 
>>> corresponding key when calling the execute method. But I'd just like 
>>> to make absolutely sure.
>>> In particular, I'm curious if the 's' actually means anything (like 
>>> string?). Should I be using different characters for different data 
>>> types, and if so, which ones?
>> You just about nailed it. You should ALWAYS use 's', too, regardless 
>> of the data type.
> The DB API says "Python extended format codes" meaning that all
> valid Python formatting codes (including their parameters) may
> be used.

Thanks both for your replies. For the curious (and the benefit of ASPN 
and google) the standard formatting codes are documented at;


If your db module says it supports 'pyformat' as the paramstyle then any 
of these format codes should be supported.

It is also interesting to note that most RDBMS have native data and/or 
datetime data types but there is no direct conversion character because 
Python doesn't have a date type (until 2.3). I'm presuming that in these 
cases (no direct type correlation) you should use the 's' conversion type.

 From the desk of Andrew J Todd esq - http://www.halfcooked.com/

More information about the DB-SIG mailing list