Some questions on using arrays.

From: Ivan Uemlianin <i(dot)a(dot)uemlianin(at)celtic(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Some questions on using arrays.
Date: 2001-07-26 09:47:06
Message-ID: 3B5FE71A.5010403@celtic.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dear People

I'm finding Postgres very useful with its support for non-atomic
data-types. I have a couple of questions about setting up and
querying arrays.

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.

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).

Any help or comments appreciated, thank you.

Ivan Uemlianin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2001-07-26 12:36:20 Re: Good random numbers in PG? And crypto-wishlist
Previous Message Joel Burton 2001-07-26 09:29:17 Re: diff's between creations of tables