Array-fields and many-to-many relations - Mailing list pgsql-hackers

From Alke
Subject Array-fields and many-to-many relations
Date
Msg-id 37C14EA1.9F6EF833@iol.it
Whole thread Raw
Responses Re: [HACKERS] Array-fields and many-to-many relations
List pgsql-hackers
Hy all!

I posted this mail on the general and sql mailing-list, but I got no
aswer, so I try to post it here;
if the question is bad-explained, please ask me more details...

I want to make a many-to-many relation on my db, and I would like to use

an array-field of the external keys...
This is what I whoul like to create:

CREATE TABLE Groups(   IDGroup             SERIAL,  -- Primary key   ...
);

CREATE TABLE Customers(   IDGroups             INT4[],  -- Multiple foreign keys   ...
);

SELECT Customers.* FROM Customers WHERE IDSearchedGroup IN
Customers.IDGroups;

IDSearchedGruop is obviously a parameter.

Well, this query doesn't work because in the SELECT ... the operator
"IN" can work only on subselect, not on array... how can I check if an
element belongs to an array or not? Performance are not critical,
because I have few groups for each Customer...

Yes, I know that the common way to make many-to-many relations is adding

a support table... but I don't like the conventional solution to this
problem... any ideas???


Paolo




pgsql-hackers by date:

Previous
From: José Soares
Date:
Subject: ERROR: pull_var_clause: Cannot handle node type 108
Next
From: Alke
Date:
Subject: OID and PL/pgSQL trigger :-(