Re: [Tutor] accessing Postgres db results by column name

2010-04-12 Thread Serdar Tumgoren
> Wanted to send along one more update about this topic. Steve Orr pointed > out in a comment on Ricardo's new recipe that there's yet another way to get > named attribute access to cursor results. > I should add the disclaimer that namedtuple is only available in Python 2.6+ _

Re: [Tutor] accessing Postgres db results by column name

2010-04-12 Thread Serdar Tumgoren
Hey folks, Wanted to send along one more update about this topic. Steve Orr pointed out in a comment on Ricardo's new recipe that there's yet another way to get named attribute access to cursor results. The secret sauce is namedtuple, "high performance" collection type. This appears to be the "c

Re: [Tutor] accessing Postgres db results by column name

2010-04-10 Thread Serdar Tumgoren
> I really like Ricardo's solution ... attribute access is a nice touch, > bookmarking it now. > > FWIW, it would seem that psycopg2 also has a DictCursor (and > DictConnection). > > http://initd.org/psycopg/docs/extras.html > > > Ah, yes, there it is. Thank you. This list rocks! __

Re: [Tutor] accessing Postgres db results by column name

2010-04-09 Thread Martin Walsh
Serdar Tumgoren wrote: > Hey everyone, > > Ricardo was nice enough to post his solution as a recipe on ActiveState. > For anyone interested in bookmarking it, here's the link: > > http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/ > > Serdar > I really like Ricardo's s

Re: [Tutor] accessing Postgres db results by column name

2010-04-09 Thread Serdar Tumgoren
Hey everyone, Ricardo was nice enough to post his solution as a recipe on ActiveState. For anyone interested in bookmarking it, here's the link: http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/ Serdar ___ Tutor maillist - T

Re: [Tutor] accessing Postgres db results by column name

2010-04-09 Thread Ricardo Aráoz
Serdar Tumgoren wrote: > Hi folks, > > Does anyone know if there's native support in psycopg2 for accessing > rows in a result-set by column name (rather than by index)? > > I'd like to be able to do something like below: > > cur.execute('select id, name from mytable') > data = cur.fetchall() > for

Re: [Tutor] accessing Postgres db results by column name

2010-04-09 Thread Serdar Tumgoren
> >>> class reg(object): > ... def __init__(self, cursor, registro): > ... for (attr, val) in zip((d[0] for d in cursor.description), > registro) : > ... setattr(self, attr, val) > > >>> for row in cursor.fetchall() : > ... r = reg(cursor, row) > ... print r.CosCPrd,