From: Gerhard <ger...@gm...> - 2002-01-17 23:16:46
|
Le 17/01/02 à 17:21, Tom Jenkins écrivit: > hello all, > we're migrating away from pygresql and i'm evaluating pypgsql along with > psycopg. i found something troubling with both adapters. when we > execute a select of this form: > select count(myfield) from mytable where mykey = myvalue > and there aren't any rows that match then we get a TypeError exception > (psycopg returns ((None,)) which is almost as bad <wink>). Similarly i > was getting the same exception on sums. Now i expected and got in > pygresql a return of ((0,)). > > is anyone else seeing this or i am missing something here I tried to reproduce what you're describing: Script started on Fri Jan 18 00:00:14 2002 gerhard@lilith:~$ psql -h gargamel gerhard Welcome to psql, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit gerhard=# create table test(id serial, name varchar(20)); NOTICE: CREATE TABLE will create implicit sequence 'test_id_seq' for SERIAL column 'test.id' NOTICE: CREATE TABLE/UNIQUE will create implicit index 'test_id_key' for table 'test' CREATE gerhard=# insert into test(name) values ('bla'); INSERT 18794 1 gerhard=# select * from test; id | name ----+------ 1 | bla (1 row) gerhard=# select count(id), sum(id) from test where id=3245; count | sum -------+----- 0 | (1 row) gerhard=# \q gerhard@lilith:~$ python2.1 Python 2.1.1+ (#1, Jan 8 2002, 00:37:12) [GCC 2.95.4 20011006 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> from pyPgSQL import PgSQL >>> import psycopg >>> db = PgSQL.connect(host="gargamel") >>> cursor=db.cursor() >>> cursor.execute("select count(id) from test where id=456") >>> print cursor.fetchall() [[0]] >>> db = psycopg.connect("host=gargamel") >>> cursor = db.cursor() >>> cursor.execute("select count(id) from test where id=456") >>> print cursor.fetchall() [(0,)] >>> gerhard@lilith:~$ exit Script done on Fri Jan 18 00:05:06 2002 I was using PostgreSQL 7.1.3 and the latest released versions of pyPgSQL and psycopg, but couldn't reproduce the problem you were describing. Could you try to produce a testcase (SQL schema and Python code) and upload it to the Sourceforge bug tracker or post it here? Or perhaps I didn't understand your question correctly!? Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) |