Skip site navigation (1) Skip section navigation (2)

Re: When I select a single column, can I prevent getting a list of one-element tuples?

From: "W(dot) Matthew Wilson" <matt(at)tplus1(dot)com>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: When I select a single column, can I prevent getting a list of one-element tuples?
Date: 2012-06-19 18:36:11
Message-ID: CAGHfCUD0HqFmAWieaBqy+Ajj=r9BKGtGtZYAbrLyNZCdTAgkxg@mail.gmail.com (view raw or flat)
Thread:
Lists: psycopg
On Sun, Jun 17, 2012 at 12:32 PM, Daniele Varrazzo
<daniele(dot)varrazzo(at)gmail(dot)com> wrote:

> No, there's nothing like this. For me, any attempt to add a feature
> and let the user choose whether to return one-column queries just as
> lists or as one-item tuples (a cursor subclass? a function?) seems
> more verbose than the [r[0] for r in cur] or map(itemgetter(0), cur)
> to get the data the way you want.

Thanks for the reply!  Mostly I wanted to make sure there wasn't
already a standard solution out there.

For me, it just feels goofy to write something like [row[0] for row in
cursor.fetchall()], but I understand where you are coming from.

I like the cursor subclass idea so maybe I'll take a shot at something
like that.

Matt

-- 
W. Matthew Wilson
matt(at)tplus1(dot)com
http://tplus1.com

In response to

Responses

psycopg by date

Next:From: Nick CashDate: 2012-06-19 20:19:08
Subject: Re: When I select a single column, can I prevent getting a list of one-element tuples?
Previous:From: Nicolas GrillyDate: 2012-06-19 11:24:18
Subject: Re: connection pooling in web apps

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group