pyPgSQL data retrieval/formatting problem - Mailing list pgsql-novice

From M C
Subject pyPgSQL data retrieval/formatting problem
Date
Msg-id SNT116-W533CFA1AD8D63003AB0686F02C0@phx.gbl
Whole thread Raw
List pgsql-novice
Hi,
I'm trying to retrieve data via a simple Python CGI script, but have run into a weird problem. Firstly, consider the simple schema:

######
CREATE TABLE sensorID (
        SensorID     VARCHAR (20) PRIMARY KEY
);

CREATE DOMAIN reason
  as text
  check (value in ('d', 'p', 't'));  -- 'd'=data, 'p'=position, 't'=tilt

CREATE TABLE manual (
        SensorID  VARCHAR (20) references sensorID(SensorID),
        Time      time without time zone,
        Date      date,
        Latitude  numeric(12,7) DEFAULT 0.0,
        Longitude numeric(12,7) DEFAULT 0.0,
        Reason    reason
);
#######


The table "manual" is populated with:

# select * from manual;
 sensorid |   time   |    date    |  latitude  | longitude | reason
----------+----------+------------+------------+-----------+--------
 UA009    | 13:43:00 | 2010-03-15 | 52.2317870 | 0.1488020 | p
 UA023    | 13:43:00 | 2010-03-15 | 52.1989030 | 0.1625360 | p
 UA031    | 13:43:00 | 2010-03-15 | 52.1990530 | 0.1398190 | p
(3 rows)

The trouble comes when I try to run a "select" via the CGI script. The simple guts of it are:

### <begin CGI script> ###

import cgi
from pyPgSQL import PgSQL
cx = PgSQL.connect(<details omitted>)
cu = cx.cursor()
cuerr = cu.execute("select * from manual")
out = cu.fetchall()
print str(out)

### <end CGI script> ###

The output gives:

out = [['UA009', , , , , 'p'], ['UA023', , , , , 'p'], ['UA031', , , , , 'p']]

As you can see, the quantities defined as strings, namely 'sensorID' and 'Reason', come out OK. But I'm losing everything else. Am I doing something silly, or missing out on some necessary formatting?

Thanks for any help,
mc




Got a cool Hotmail story? Tell us now

pgsql-novice by date:

Previous
From: John Gage
Date:
Subject: Re: DIFFERENCE BETWEEN LIKE AND SIMILAR OPERATORS
Next
From: Tav
Date:
Subject: row v column numbers