Re: [GENERAL] questing using array

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Kevin Heflin <kheflin(at)shreve(dot)net>
Cc: "PGSQL-General (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: [GENERAL] questing using array
Date: 1999-10-13 20:09:39
Message-ID: Pine.LNX.4.10.9910132203430.2573-100000@peter-e.yi.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You might want to look into the contrib/array directory which has _some_
helpers with arrays.

But in general, using arrays in cases like yours is a bad idea because,
a) It has nothing to do with relational database design
b) Arrays were not designed for this kind of stuff, so you won't get very
far.

Regarding a), redesign your table like this
name varchar(20)
ageid int4

and make the records like this:
test 1
test 2
test 3
test 4

and then you can use a simple select to find your answer. (Yes, this looks
like you're storing more data, but that is how things are supposed to
work.)

Regarding b), arrays were created mostly for geometric objects. Of course
you still could ask questions like "give me a polygon that has some
coordinate that has a 20 in it", but it's unlikely and specialty functions
exist to deal with questions you would usually have.

-Peter

On Oct 12, Kevin Heflin mentioned:
>
> Just trying to get a handle on how to work with an array as a datatype.
>
> For exampel I set up a table:
>
> name varchar (20),
> ageids int4[]
>
>
> Made an INSERT like:
>
> insert into TABLENAME (name, ageids) values ('test', '{1, 2, 3, 4}');
>
>
> What I haven't been able to figure out is how to do a select where one of
> the ageids = a particular number.
>
>
> I'd like to do something like
> select * from tablename where ( any ageids = 3 )
>
> just don't know the syntax.. if this is even possible. Any suggestions
> would be appreciated.

--
Peter Eisentraut Sernanders vaeg 10:115
peter_e(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Yin-So Chen 1999-10-13 20:44:47 Re: [GENERAL] stored procedure revisited
Previous Message Peter Eisentraut 1999-10-13 19:56:15 Re: [GENERAL] How do I activate and change the postgres user's password?