Re: How to join table to itself N times?

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: How to join table to itself N times?
Дата
Msg-id CAOR=d=21C3sJ49A8M7TbFz4NbdqvYRTJFkhzT98595n20gEcsg@mail.gmail.com
обсуждение исходный текст
Ответ на How to join table to itself N times?  ("W. Matthew Wilson" <matt@tplus1.com>)
Ответы Re: How to join table to itself N times?  (Paul Jungwirth <pj@illuminatedcomputing.com>)
Список pgsql-general
On Wed, Mar 20, 2013 at 5:38 PM, W. Matthew Wilson <matt@tplus1.com> wrote:
> I got this table right now:
>
> select * from market_segment_dimension_values ;
> +--------------------------+---------------+
> | market_segment_dimension |     value     |
> +--------------------------+---------------+
> | geography                | north         |
> | geography                | south         |
> | industry type            | retail        |
> | industry type            | manufacturing |
> | industry type            | wholesale     |
> +--------------------------+---------------+
> (5 rows)
>
> The PK is (market_segment_dimension, value).
>
> The dimension column refers to another table called
> market_segment_dimensions.
>
> So, "north" and "south" are to values for the "geography" dimension.
>
> In that data above, there are two dimensions.  But sometimes there could be
> just one dimension, or maybe three, ... up to ten.

If the number of dimensions is not fixed, then you'll probably have to
write a plpgsql function to first interrogate the data set for how
many dimensions there are and then to build an n-dimension query.
While joining a variable number of tables may be problematic as you
won't have a fixed number of columns, using a union might give you
what you want with a fixed number of columns.


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

Предыдущее
От: AI Rumman
Дата:
Сообщение: Re: How to join table to itself N times?
Следующее
От: John R Pierce
Дата:
Сообщение: Re: postgresql-9.1.2 - Linux