pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Joÿffffffffffe3o Carvalho <joaocarvalho127@yahoo.com.br>
Cc: pgsql-sql@postgresql.org
Subject: Re: queries problems
Date: Thu, 8 Sep 2005 17:54:35 -0600
Message-ID: <20050908235435.GA68913@winnie.fuhr.org> (raw)
In-Reply-To: <20050908223348.21917.qmail@web50614.mail.yahoo.com>
References: <20050902020346.GA58397@winnie.fuhr.org>
	<20050908223348.21917.qmail@web50614.mail.yahoo.com>

On Thu, Sep 08, 2005 at 10:33:48PM +0000, Joÿffffffffffe3o Carvalho wrote:
> The problem here is to compare int2vector with int2.

Presumably you're talking about joining pg_index.indkey against
pg_attribute.attnum -- is that correct?  Will pg_get_indexdef() not
work for your needs?

I don't know if there's an easier way to check if an int2 is a
member of an int2vector, but you could write a function to convert
an int2vector to an int2 array and then use an "= ANY" expression.
The following seems a little ugly, but it works for me in simple
tests:

CREATE FUNCTION int2vector2array(int2vector) RETURNS int2[] AS $$
BEGIN
    RETURN string_to_array(textin(int2vectorout($1)), ' ');
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

SELECT 2::smallint = ANY (int2vector2array('1 2 3'));
 ?column? 
----------
 t
(1 row)

SELECT 4::smallint = ANY (int2vector2array('1 2 3'));
 ?column? 
----------
 f
(1 row)

Improvements or other suggestions welcome.

-- 
Michael Fuhr



view thread (6+ messages)  latest in thread

Message-ID: <20050908235435.GA68913@winnie.fuhr.org>
Permalink:  ../20050908235435.GA68913@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050908235435.GA68913@winnie.fuhr.org

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, joaocarvalho127@yahoo.com.br
  Subject: Re: queries problems
  In-Reply-To: <20050908235435.GA68913@winnie.fuhr.org>

* 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