From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jon Nelson <jnelson+pgsql@jamponi.net>
Cc: pgsql-bugs@postgresql.org
Subject: Re: database introspection error
Date: Thu, 21 Apr 2011 12:28:51 -0400
Message-ID: <24590.1303403331@sss.pgh.pa.us> (raw)
In-Reply-To: <BANLkTineAbe68mrzpuF7VY5Ag5MGqc+_cQ@mail.gmail.com>
References: <BANLkTineAbe68mrzpuF7VY5Ag5MGqc+_cQ@mail.gmail.com>
Jon Nelson <jnelson+pgsql@jamponi.net> writes:
> SQLAlchemy encountered an error introspecting the tables. After
> inspecting the SQL that it was running, I boiled it down to this:
> SELECT c.relname, a.attname
> FROM pg_index i, pg_class c, pg_attribute a
> WHERE i.indrelid = '16684' AND i.indexrelid = c.oid
> AND a.attrelid = i.indexrelid
> ORDER BY c.relname, a.attnum;
> I believe that SQL gives me the name of an index and the attribute
> upon which that index is built for a particular relation (16684).
> However, the *results* of that query are _wrong_. The 'attname' value
> for one row is wrong. It is the *previous* name of the column.
That appears to be pulling out the names of the columns of the index,
not the underlying table. While older versions of Postgres will try to
rename index columns when the underlying table column is renamed, that
was given up as an unproductive activity awhile ago (mainly because
there isn't always a 1-to-1 mapping anyway). So it's not surprising
to me that you're getting "stale" data here.
You might want to have a discussion with the SQLAlchemy people about
what it is that they're trying to accomplish and how it might be done
in a more bulletproof fashion. The actual names of the columns of an
index are an implementation detail that shouldn't be relied on.
regards, tom lane
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, jnelson+pgsql@jamponi.net
Subject: Re: database introspection error
In-Reply-To: <24590.1303403331@sss.pgh.pa.us>
References: <BANLkTineAbe68mrzpuF7VY5Ag5MGqc+_cQ@mail.gmail.com> <24590.1303403331@sss.pgh.pa.us>
* 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