Stephan K.
Stephan K.

Reputation: 15722

Python psycopg2: Access Tuple

We have a PostGres Database which I am accessing with Python. When Querying for a column with type bigint I get back a dictionary with in the following format:

 [[263778L], [30188L], [97L], [12215192L], [702819L], [1301581L], [11101568L], [4712L], [1107866L]]

I need to add these values up together, but I cannot access them as integers.

Fails:

...
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("SELECT column1 FROM relation1
rec = cur.fetchall()
for row in rec:
    print(re.findall('\d+', row))

Python is returning:

TypeError: expected string or buffer

How to achieve what I want?

Upvotes: 0

Views: 531

Answers (1)

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125284

This is a list of lists:

[[263778L], [30188L], [97L], [12215192L], [702819L], [1301581L], [11101568L], [4712L], [1107866L]]

not a dictionary. To print each value:

for row in rec:
    print(row[0])

Upvotes: 1

Related Questions