Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 670ED1337BD3 for ; Thu, 21 Apr 2011 13:29:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 85040-06-2 for ; Thu, 21 Apr 2011 16:28:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id CAC491337C02 for ; Thu, 21 Apr 2011 13:28:52 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p3LGSp4Z024591; Thu, 21 Apr 2011 12:28:51 -0400 (EDT) To: Jon Nelson cc: pgsql-bugs@postgresql.org Subject: Re: database introspection error In-reply-to: References: Comments: In-reply-to Jon Nelson message dated "Thu, 21 Apr 2011 10:45:14 -0500" Date: Thu, 21 Apr 2011 12:28:51 -0400 Message-ID: <24590.1303403331@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/174 X-Sequence-Number: 30093 Jon Nelson 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