Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 4309D9FB709 for ; Mon, 11 Jun 2007 03:29:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 26497-02 for ; Mon, 11 Jun 2007 03:29:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 1D1F19FB6EA for ; Mon, 11 Jun 2007 03:29:27 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail.skype.net (mail.skype.net [193.88.6.4]) by svr4.postgresql.org (Postfix) with ESMTP id 283F45AF02C for ; Mon, 11 Jun 2007 06:29:26 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mail.skype.net (Postfix) with ESMTP id 7A7B8110169; Mon, 11 Jun 2007 08:27:02 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.skype.net Received: from mail.skype.net ([127.0.0.1]) by localhost (mail.skype.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tKFk62pbWsUe; Mon, 11 Jun 2007 08:27:02 +0200 (CEST) Received: from [10.20.0.92] (gprs-inet.elisa.ee [194.150.66.11]) by mail.skype.net (Postfix) with ESMTP id 3C94D110165; Mon, 11 Jun 2007 08:26:29 +0200 (CEST) In-Reply-To: <112402456@web.de> References: <112402456@web.de> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit From: Kristo Kaiv Subject: Re: show index from [table] Date: Mon, 11 Jun 2007 09:28:13 +0300 To: Stefan Zweig X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/80 X-Sequence-Number: 28570 On 08.06.2007, at 18:25, Stefan Zweig wrote: > > but actually i would need the information from within a (postgres) > sql-query. is there a possibility to get information about the > indices which have been created on a table? > > if there is not, it might be sufficient for me to get the create > index strings, such like you get, when viewing a table in pgAdmin: you can turn on echoing of psql commands sent to server with: psql -E dbname from there you can get the queries needed: find the oid of table (unique object id) ********* QUERY ********** SELECT c.oid, n.nspname, c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname ~ '^(miljon)$' AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 2, 3; find table indices (replace the oid by the value found with your previous query) ********* QUERY ********** SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, i.indisvalid, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), c2.reltablespace FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i WHERE c.oid = '16427' AND c.oid = i.indrelid AND i.indexrelid = c2.oid ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname here is my sample output: relname | indisprimary | indisunique | indisclustered | indisvalid | pg_get_indexdef | reltablespace --------------+--------------+-------------+---------------- +------------ +------------------------------------------------------------ +--------------- miljon_pkey | t | t | f | t | CREATE UNIQUE INDEX miljon_pkey ON miljon USING btree (id) | 0 idx_blahblah | f | f | f | t | CREATE INDEX idx_blahblah ON miljon USING btree (sisu) | 0 (2 rows) hope this helps Kristo