X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 346AAD8B08 for ; Thu, 8 Sep 2005 20:54:39 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63796-03 for ; Thu, 8 Sep 2005 23:54:35 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 1262CD8B1E for ; Thu, 8 Sep 2005 20:54:36 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j88NsaQW038011 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 8 Sep 2005 17:54:39 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j88NsagR069000; Thu, 8 Sep 2005 17:54:36 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j88Nsap8068999; Thu, 8 Sep 2005 17:54:36 -0600 (MDT) (envelope-from mfuhr) Date: Thu, 8 Sep 2005 17:54:35 -0600 From: Michael Fuhr To: =?iso-8859-1?Q?Jo=FFffffffffffe3o?= Carvalho Cc: pgsql-sql@postgresql.org Subject: Re: queries problems Message-ID: <20050908235435.GA68913@winnie.fuhr.org> References: <20050902020346.GA58397@winnie.fuhr.org> <20050908223348.21917.qmail@web50614.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20050908223348.21917.qmail@web50614.mail.yahoo.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005] X-Spam-Level: X-Archive-Number: 200509/96 X-Sequence-Number: 22643 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