Re: Links between rows in a table

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: Links between rows in a table
Дата
Msg-id 20050306174201.GA19019@wolff.to
обсуждение исходный текст
Ответ на Links between rows in a table  (Stefan Weiss <spaceman@foo.at>)
Ответы Re: Links between rows in a table  (Stefan Weiss <spaceman@foo.at>)
Список pgsql-sql
On Sun, Mar 06, 2005 at 05:42:14 +0100, Stefan Weiss <spaceman@foo.at> wrote:
> 
> We are currently designing a web-based application in which users can
> add other users as "friends". These links are bi-directional, meaning
> that when A adds B to his friends, he is automatically one of B's
> friends. Eventually we will have to add a feature that shows how A is

This doesn't seem like a good idea unless the person getting linked to
gets to confirm he wants the link creator as a friend.

> I can see several ways how such links could be modeled in a relational
> database, but I was wondering if there was some tried-and-true recipe
> that would spare me from reinventing the wheel. Putting aside for the
> moment everything but the links, the simplest way of connecting users
> would be a "friends" table (user_id int, friend_id int). We could get a
> user's friends with a simple query like this:
> 
>         SELECT friend_id FROM friends WHERE user_id   = X
>   UNION SELECT user_id   FROM friends WHERE friend_id = X;

It would probably be better to always have either both or neither of
the symmetric relationships in the table. You could make a set of triggers
to enforce this.


В списке pgsql-sql по дате отправления:

Предыдущее
От: bandeng
Дата:
Сообщение: count array in postgresql
Следующее
От: Stefan Weiss
Дата:
Сообщение: Re: Links between rows in a table