[DB-SIG] any 2.0-compliant packages for postgresql?

Federico Di Gregorio fog@mixadlive.com
27 Jun 2001 16:38:26 +0200


On 27 Jun 2001 07:25:49 -0700, Nathan Clegg wrote:
> > Q: psycopg correctly put strings obtained by the Date and Time
> > constructors inside quotes  ('') as requested by the api. it should do
> > the same (and maybe escape) normal strings? if that's the case don't we
> > need a String constructor? how is the module supposed to know when a
> > string is real string and need quoting and when i am passing it just as
> > convenience but it really is a number? example...
> 
> This is the part I have issue with.  The api spec does require that normal
> strings be escaped and quoted.  In regards to passing numbers as strings for
> convenience, I would suggest doing away with it.  If you mean it to be a
> number, send a number, and furthermore specify %(name)d instead of %(name)s.
> I appreciate conveniences, but I think this introduces the kind of ambiguity
> that python's specification set out to squash in the first place.
> Furthermore, all of the databases I have personally used have no problem
> casting strings to numbers where required.  That is, if you pass postgresql
> (or oracle, or mysql...) a quoted string '768' to compare against a number
> field, it with cast it to a number for you and get you the desired result.
> The module doesn't really need to implement this convenience casting because
> the database engine already does.


so, if i try to do as follows:

curs.execute("CREATE TABLE test (a text)")
curs.execute("INSERT INTO test VALUES (%(a)s)", {'a':'some text...'})

the method call fails miserably because the generated SQL is:

    INSERT INTO test VALUES (some text...)

without quotes. footnote 5 requires argument binding to prodive quotes
and escape sequences but how can the module know is the given string
will be a string in the db too and requires quoting or it is something
different (let's say a user-defined type in psogresql) that does not
require it?

anyway, your answer at least means that psycopg isn't more broken that
all other drivers... ;)

ciao,
federico

-- 
Federico Di Gregorio
MIXAD LIVE Chief of Research & Technology              fog@mixadlive.com
Debian GNU/Linux Developer & Italian Press Contact        fog@debian.org
   God is real. Unless declared integer. -- Anonymous FORTRAN programmer