pyPgSQL data retrieval/formatting problem

From: M C <m_c_001(at)hotmail(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: pyPgSQL data retrieval/formatting problem
Date: 2010-03-17 12:24:19
Message-ID: SNT116-W533CFA1AD8D63003AB0686F02C0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
http://clk.atdmt.com/UKM/go/195013117/direct/01/

Browse pgsql-novice by date

  From Date Subject
Next Message Felix Obermaier 2010-03-17 13:38:29 Drop table by something other than its name
Previous Message Jasen Betts 2010-03-16 08:51:31 Re: PostgreSQL questions