Re: Atrybutes ???

From: Jeff Davis <jdavis-pgsql(at)empires(dot)org>
To: Grendel <postgres(at)isukces(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Atrybutes ???
Date: 2003-10-23 08:27:00
Message-ID: 1066897620.27164.13.camel@jeff
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2003-10-22 at 10:27, Grendel wrote:
> Hello !!!
> I have store some attrybutes to database. Attrybutes are set of integer values.
> {1,5,7} is valid set, but {1,3,1} is not valid set
>
> I have to build compare relation i.e.
> {1,5,7} is equivalent to {5,7,1} or {1,7,5} etc.
> but
> {1,5,7} is not equivalent to {5,1} or {1,4,2}
>
> What's best solution: arrays, master detail relation, something else...

I suggest that you make a separate relation with an int attribute and a
foreign key referencing the main relation. Then just make a unique index
on the combination of the foriegn key value and the integer value.

example:

CREATE TABLE main (
id int4 primary key,
attr2 type2,
attr3 type3
);
CREATE TABLE set_of_ints (
id int4 references main(id),
val int
);
CREATE UNIQUE INDEX set_uniq_idx ON set_of_ints(id,val);

Then you have the necessary constraints on data, and you can get the
sets in any order you like.

Arrays aren't the answer to this problem, because an array is not a set,
and arrays don't give you the benefits of relational operations.

Jeff

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2003-10-23 11:47:19 Re: Trigger
Previous Message Mark Kirkwood 2003-10-23 08:09:51 Re: Recomended FS (correction)