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

From Alke
Subject Array-fields and many-to-many relations
Date
Msg-id 37BDC865.9BB15F3E@iol.it
Whole thread Raw
List pgsql-general
Hy all!

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

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-general by date:

Previous
From: "G. Anthony Reina"
Date:
Subject: RE: [GENERAL] Error during 'vacuum analyze'
Next
From: "Dmitri G. Chtchekine"
Date:
Subject: pq_recvbuf: unexpected EOF on client connection