Mailing List Archive

bug in PyGreSQL module
I found an apparent bug in the Python interface to PostgreSQL. I
tried sending a query to the author but haven't heard back, so I'm
looking for other users to see if they have run into the problem.
I have a table with lots of int fields, some of which of NULL. When I
do a Python query, the PyGreSQL module converts the NULL to 0 instead
of None, which is the value I expected. Is that a reasonable
expectation?

The PyGreSQL module doesn't implement the DB API, but I checked there
anyway. Alas, it didn't say anything about how to handle NULL.

Jeremy
bug in PyGreSQL module [ In reply to ]
On Tue, 13 Apr 1999, Jeremy Hylton wrote:
> I found an apparent bug in the Python interface to PostgreSQL. I
> tried sending a query to the author but haven't heard back, so I'm
> looking for other users to see if they have run into the problem.
> I have a table with lots of int fields, some of which of NULL. When I
> do a Python query, the PyGreSQL module converts the NULL to 0 instead
> of None, which is the value I expected. Is that a reasonable
> expectation?

I have not noted such problem, I am using PyGres quite happily. Which
version you are using?

> The PyGreSQL module doesn't implement the DB API, but I checked there
> anyway. Alas, it didn't say anything about how to handle NULL.

DB API will be implemented in the upcominh PyGres 3.0.

> Jeremy

Oleg.
----
Oleg Broytmann National Research Surgery Centre http://sun.med.ru/~phd/
Programmers don't die, they just GOSUB without RETURN.
bug in PyGreSQL module [ In reply to ]
I'm using PyGreSQL 2.3, Postgres 6.4.2, and Python 1.5.2b2 on RedHat
Linux 5.2. (That's a lot of version numbers!)

Here's an example of the error. I've extracted the three rows from a
table (and gotten ride of the date because it's too wide). As you
can see, in the first two rows the min, average, and max fields are
empty.

source|source_addr|dest|dest_addr|when|size|sent|recv|min|average|max
------+-----------+----+---------+----+----+----+----+---+-------+---
19| 41| 6| 6|XXXX| 100| 10| 0| | |
19| 41| 6| 6|XXXX|1000| 10| 0| | |
19| 41| 6| 6|XXXX| 100| 10| 4|120| 184|245

If I perform the query in Python and then call the getresult method, I
get back the following list:

[.(19, 41, 6, 6, 'Tue Apr 13 00:46:05 1999 EDT', 100, 10, 0, 0, 0, 0),
(19, 41, 6, 6, 'Tue Apr 13 00:45:14 1999 EDT', 1000, 10, 0, 0, 0, 0),
(19, 41, 6, 6, 'Tue Apr 13 00:16:05 1999 EDT', 100, 10, 4, 120, 184, 245)]

The nulls have been converted to 0. This seems straightforward given
the C code in getresult. If the field is an integer, the libpq value
is always handed off to PyInt_FromLong. I would think that there
should be an explicit check for NULLs in pg_getresult that converts
them to None.

Jeremy
bug in PyGreSQL module [ In reply to ]
On Tue, 13 Apr 1999, Jeremy Hylton wrote:
> The nulls have been converted to 0. This seems straightforward given
> the C code in getresult. If the field is an integer, the libpq value
> is always handed off to PyInt_FromLong. I would think that there
> should be an explicit check for NULLs in pg_getresult that converts
> them to None.

Have you subscribed to PyGres mailing list? Contact the list and report
this.

> Jeremy
>

Oleg.
----
Oleg Broytmann National Research Surgery Centre http://sun.med.ru/~phd/
Programmers don't die, they just GOSUB without RETURN.
bug in PyGreSQL module [ In reply to ]
Jeremy Hylton wrote:
>
> I found an apparent bug in the Python interface to PostgreSQL. I
> tried sending a query to the author but haven't heard back, so I'm
> looking for other users to see if they have run into the problem.
> I have a table with lots of int fields, some of which of NULL. When I
> do a Python query, the PyGreSQL module converts the NULL to 0 instead
> of None, which is the value I expected. Is that a reasonable
> expectation?
>
> The PyGreSQL module doesn't implement the DB API, but I checked there
> anyway. Alas, it didn't say anything about how to handle NULL.

Database interface modules should use None as reprensentation
of SQL NULL values on the Python side of things; in fact most
interfaces already take this intuitive approach.

--
Marc-Andre Lemburg Y2000: 261 days left
---------------------------------------------------------------------
: Python Pages >>> http://starship.skyport.net/~lemburg/ :
---------------------------------------------------------