Re: Some questions on using arrays.

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Ivan Uemlianin <i(dot)a(dot)uemlianin(at)celtic(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Some questions on using arrays.
Date: 2001-08-13 16:45:36
Message-ID: Pine.BSF.4.21.0108130941140.64246-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 26 Jul 2001, Ivan Uemlianin wrote:

> If this kind of thing is more for pgsql-novice, please let me know.
>
> Questions refer to the following table.
>
> create table bar ( id serial, links int4[] )
>
> id | links
> ----+---------
> 1 | {2,3,4}
> 2 | {3,4,5}
> 3 | {4,5,6}
> 4 | {5,6,7}
> 5 | {6}
> 6 | {4,5,7}
> 7 | {1,3,5}
>
> 1. How do I query the contents of an array? For the example table I'd
> like to say something like 'select * from bar where links contains
> 5', but operators like in, @ and ~ don't seem to work.

You probably want to look in contrib. There's a bunch of array
functions and operators in there.

> 2. Imagine the table is a directed graph (e.g. a map of one-way
> streets between locations). I'd like to have each element of links
> to be a reference to id (or a similar field in another table).

Well, you can make it store ids of the other field, you'd have to make
your own triggers to enforce integrity if you wanted it to be done by
the db.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jova 2001-08-13 17:30:50 spool
Previous Message Tim Barnard 2001-08-13 16:01:23 Re: delete columns from table!