Re: Question(s) about crosstab

Поиск
Список
Период
Сортировка
Искать
От
Sergey Konoplev
Тема
Re: Question(s) about crosstab
Дата
Msg-id
CAL_0b1sK7begHU0ms=Cks9gGmr-9LGtF9H02Ht+WQYV_jSN_aQ@mail.gmail.com
Ответ на
Список
Дерево обсуждения
Question(s) about crosstab Ken Tanzer <ken.tanzer@gmail.com>
Re: Question(s) about crosstab rob stone <floriparob@gmail.com>
Re: Question(s) about crosstab Ken Tanzer <ken.tanzer@gmail.com>
Re: Question(s) about crosstab David Johnston <polobo@yahoo.com>
Re: Question(s) about crosstab Ken Tanzer <ken.tanzer@gmail.com>
Re: Question(s) about crosstab Scott Marlowe <scott.marlowe@gmail.com>
Re: Question(s) about crosstab AI Rumman <rummandba@gmail.com>
Re: Question(s) about crosstab Sergey Konoplev <gray.ru@gmail.com>
On Tue, Dec 17, 2013 at 3:31 PM, Ken Tanzer  wrote:
> 1)  Is there a simpler way?  I'm hoping I made this unnecessarily cumbersome and complicated.
> 2)  AFAICT, if a new unit type were to be added, I'd have to rewrite this query.  Is there any way to avoid that?
> 3)  It seems like everything after the first query, except for the category field, is redundant information, and that in theory you should be able to say crosstab('query','category_field').  Is there any inherent reason this simpler form couldn't work, or is it just that no one has wanted to do it, or gotten to it yet?

Try to look at this article [1]. The guy has made some plpgsql
automation so it generate the resulting crostab query kind of like you
described it in 3, and it looks like is solves 1 and 2. For complex
queries you can make views and use them with the tablename argument.

[1] http://www.cureffi.org/2013/03/19/automatically-creating-pivot-table-column-names-in-postgresql/

-- 
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray.ru@gmail.com

В списке pgsql-general по дате отправления
От: Joe Conway
Дата:
Сообщение: Re: Question(s) about crosstab
От: Scott Marlowe
Дата:
Сообщение: Re: Multi Master Replication
FAQ