简体   繁体   中英

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?

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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM