From: Adrian Klaver <adrian.klaver@aklaver.com>
To: David G. Johnston <david.g.johnston@gmail.com>
To: tango ward <tangoward15@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: KeyError: self._index[x]
Date: Mon, 7 May 2018 21:06:55 -0700
Message-ID: <661c8f00-ba13-3806-b7bd-2f05159df9b4@aklaver.com> (raw)
In-Reply-To: <CAKFQuwbQ4NFdOsnynqK6OAmdbFUsOjT+LtuNdfA6SFqBCQc6YA@mail.gmail.com>
References: <CAA6wQLJGd-c8rqAetCrk4QMAqFGaX-dqTMVAc934PptvrKqVrg@mail.gmail.com>
<CAA6wQL+vkvVYLhHJ_zcq+w-cdJb78qwVB2KvQSxXz-T3FY0wag@mail.gmail.com>
<CAKFQuwbQ4NFdOsnynqK6OAmdbFUsOjT+LtuNdfA6SFqBCQc6YA@mail.gmail.com>
On 05/07/2018 08:50 PM, David G. Johnston wrote:
> On Monday, May 7, 2018, tango ward <tangoward15@gmail.com
> <mailto:tangoward15@gmail.com>> wrote:
>
>
> cur_t.execute("""
> SELECT TRANSLATE(snumber, ' ', '')
> FROM sprofile """)
>
> # This will result in KeyError
> for row in cur_t:
> print row['snumber']
>
> # This works fine
> for row in cur_t:
> print row[0]
>
>
> So apparently when you execute your query the result has at least one
> column but that column isn't named "snumber". I'm sure there is a way
> in Python to debug "row" and find out what names it does have. Or maybe
Python 3+
print(row)
Python 2.7
print row
> execute the query in something like psql and observe e column name there.
>
> That said, by default the name of columns whose values are derived by a
> single function call should be the name of the function. So
> "translate", not "snumber" - the latter being consumed by the function.
> You can as use "as <alias>" to give it a different fixed name and refer
> to that.
>
> David J.
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, david.g.johnston@gmail.com, tangoward15@gmail.com
Subject: Re: KeyError: self._index[x]
In-Reply-To: <661c8f00-ba13-3806-b7bd-2f05159df9b4@aklaver.com>
References: <CAA6wQLJGd-c8rqAetCrk4QMAqFGaX-dqTMVAc934PptvrKqVrg@mail.gmail.com> <CAA6wQL+vkvVYLhHJ_zcq+w-cdJb78qwVB2KvQSxXz-T3FY0wag@mail.gmail.com> <CAKFQuwbQ4NFdOsnynqK6OAmdbFUsOjT+LtuNdfA6SFqBCQc6YA@mail.gmail.com> <661c8f00-ba13-3806-b7bd-2f05159df9b4@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox