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

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: "W(dot) Matthew Wilson" <matt(at)tplus1(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-17 16:32:58
Message-ID: CA+mi_8Y6UXtAmYKKBZAHBoY7F6giuT5WfE0wi3hR44XXYDsXzg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Sun, Jun 17, 2012 at 4:55 PM, W. Matthew Wilson <matt(at)tplus1(dot)com> wrote:

> I understand that when I ask for more than one column in a query,
> psycopg2 MUST return each row as a list.  But when I am asking for
> exactly one column, is there a way to tell psycopg2 to not return a
> list for every row, but just the single value?

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.

-- Daniele

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2012-06-17 18:02:17 Re: Capacity questions
Previous Message W. Matthew Wilson 2012-06-17 15:55:15 When I select a single column, can I prevent getting a list of one-element tuples?