From: Haller Christoph <ch@rodos.fzk.de>
To: josteinu@sylfest.hiof.no
Cc: pgsql-sql@postgresql.org
Subject: Re: How to find primary keys by querying system tables
Date: Thu, 25 Oct 2001 16:47:02 METDST
Message-ID: <200110251447.QAA02147@rodos> (raw)
>
> Is there a way of testing for membership in an int2vector-field? For
> example:
> select column, "prim.key" from ... where pg_attribute.attnum in
> pg_index.indkey
> ??
>
I think so. Refer to the array section of the documentation.
Extract:
To search for a value in an array, you must check each value of the array. This can be done by hand (if you know the size of the array):
SELECT * FROM sal_emp WHERE pay_by_quarter[1] = 10000 OR
pay_by_quarter[2] = 10000 OR
pay_by_quarter[3] = 10000 OR
pay_by_quarter[4] = 10000;
However, this quickly becomes tedious for large arrays, and is not helpful if the size of the array is unknown. Although it is not part of the primary
PostgreSQL distribution, in the contributions directory, there is an extension to PostgreSQL that defines new functions and operators for iterating
over array values. Using this, the above query could be:
SELECT * FROM sal_emp WHERE pay_by_quarter[1:4] *= 10000;
To search the entire array (not just specified columns), you could use:
SELECT * FROM sal_emp WHERE pay_by_quarter *= 10000;
In addition, you could find rows where the array had all values equal to 10 000 with:
SELECT * FROM sal_emp WHERE pay_by_quarter **= 10000;
To install this optional module, look in the contrib/array directory of the PostgreSQL source distribution.
Regards, Christoph
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: ch@rodos.fzk.de, josteinu@sylfest.hiof.no
Subject: Re: How to find primary keys by querying system tables
In-Reply-To: <200110251447.QAA02147@rodos>
* 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