X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 4D990D1B4D8 for ; Thu, 29 Jan 2004 17:12:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 19551-03 for ; Thu, 29 Jan 2004 13:11:54 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 70D6BD1C967 for ; Thu, 29 Jan 2004 13:11:52 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i0THBp48024239; Thu, 29 Jan 2004 12:11:52 -0500 (EST) To: Rich Cullingford Cc: pgsql-admin@postgresql.org Subject: Re: How to use int2vector In-reply-to: <401932E9.4010702@sysd.com> References: <401932E9.4010702@sysd.com> Comments: In-reply-to Rich Cullingford message dated "Thu, 29 Jan 2004 11:20:57 -0500" Date: Thu, 29 Jan 2004 12:11:51 -0500 Message-ID: <24238.1075396311@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/272 X-Sequence-Number: 12135 Rich Cullingford writes: > In trying to write a utility to drop/restore table indexes (as an aid to > a fast reload of the associated tables), I ran into the definition of > the field pg_index.indkey as an int2vector. > How can I deal with this type in plpgsql? You should be able to index into it (indkey[0], etc), but I cannot think of any good reason to be looking at the details of the pg_index row for your purposes. It is certainly not reasonable to think of writing plpgsql code to reconstruct 7.4 expressional index definitions from what's in pg_index :-(. I would suggest using the pg_get_indexdef function instead. Perhaps something like regression=# select pg_get_indexdef(indexrelid) from pg_index where indrelid = 'tenk1'::regclass; pg_get_indexdef ----------------------------------------------------------- CREATE INDEX tenk1_hundred ON tenk1 USING btree (hundred) CREATE INDEX tenk1_unique2 ON tenk1 USING btree (unique2) CREATE INDEX tenk1_unique1 ON tenk1 USING btree (unique1) (3 rows) regression=# pg_get_indexdef() exists at least as far back as 7.0, and probably further (pg_dump has relied on it for a long time). regards, tom lane