pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Rich Cullingford <rculling@sysd.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: How to use int2vector
Date: Thu, 29 Jan 2004 12:11:51 -0500
Message-ID: <24238.1075396311@sss.pgh.pa.us> (raw)
In-Reply-To: <401932E9.4010702@sysd.com>
References: <401932E9.4010702@sysd.com>

Rich Cullingford <rculling@sysd.com> 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



view thread (2+ messages)

Message-ID: <24238.1075396311@sss.pgh.pa.us>
Permalink:  ../24238.1075396311@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24238.1075396311@sss.pgh.pa.us

 · 

reply

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rculling@sysd.com
  Subject: Re: How to use int2vector
  In-Reply-To: <24238.1075396311@sss.pgh.pa.us>
  References: <401932E9.4010702@sysd.com> <24238.1075396311@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