Обсуждение: Query-ing arrays
Stupid FAQ probably:
Is it possible to query an array for an item WITHOUT KNOWING where in the
array the item might be held?
For example, I have a tbale with the following character array:
> category char(3)[],
I would like to find all records in which 'category' contains an array
element of a certain type, like maybe 'xxx' for instance. So, for a
particular record, 'category' may be set to '{'gfe','qwe','xcs','xxx'}'
I cannot do:
SELECT * FROM blah WHERE category[4]='xxx';
because I do not know that the 'xxx' will always be in the 4th position.
Suggestions? TIA, Jon
--
-**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---Jon LaphamCentro Nacional de Ressonancia
MagneticaNuclear de MacromoleculasUniversidade Federal do Rio de Janeiro (UFRJ) - Brasilemail:
jlapham@gandalf.bioqmed.ufrj.br
***-*--*----*-------*------------*--------------------*---------------
I'd suggest checking the array utilities in contrib. I believe
it has functions/operators for element in set.
Stephan Szabo
sszabo@bigpanda.com
On Fri, 1 Sep 2000, Jon Lapham wrote:
> Stupid FAQ probably:
>
> Is it possible to query an array for an item WITHOUT KNOWING where in the
> array the item might be held?
>
> For example, I have a tbale with the following character array:
> > category char(3)[],
>
> I would like to find all records in which 'category' contains an array
> element of a certain type, like maybe 'xxx' for instance. So, for a
> particular record, 'category' may be set to '{'gfe','qwe','xcs','xxx'}'
>
> I cannot do:
> SELECT * FROM blah WHERE category[4]='xxx';
> because I do not know that the 'xxx' will always be in the 4th position.
On Fri, Sep 01, 2000 at 09:07:35AM -0700, Stephan Szabo wrote: > > I'd suggest checking the array utilities in contrib. I believe > it has functions/operators for element in set. Thanks, that looks like exactly what I need. I wonder if someone could put a reference to this array utility package in the manual, chapter 8, on arrays. Maybe something like this: For more complex work with arrays, see Massimo Dal Zotto's contrib package 'array_iterator'. This loadable module "...defines a new class of functions which take an array and a scalar value, iterate a scalar operator over the elements of the array and the value, and compute a result as the logical OR or AND of the iteration results." -- -**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---Jon LaphamCentro Nacional de Ressonancia MagneticaNuclear de MacromoleculasUniversidade Federal do Rio de Janeiro (UFRJ) - Brasilemail: jlapham@gandalf.bioqmed.ufrj.br ***-*--*----*-------*------------*--------------------*---------------