Double Denormalizing in Postgres

Поиск
Список
Период
Сортировка
От Robert James
Тема Double Denormalizing in Postgres
Дата
Msg-id CAGYyBggDaLCkMM3wcWvmy_1wwaOJrP=UwOTiWhMMehVhVvGdvQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Double Denormalizing in Postgres  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-general
To match the heavily denormalized format of a legacy app, I need to
take a query which gives this:

name | product | rent | own
Bob | Car | true | false
Bob | Car | false | true
Bob | Bike | false | true
Bob | Truck | true | true

and denormalize it into this:

name | rented_products | owned_products
Bob | {Car, Truck} | {Car, Truck, Bike}

I thought I could do this using array_agg, but I don't see how to do
that on a condition.  In pseudocode, I'd like to do this:
SELECT
uniq(array_agg(product WHERE rent)) AS rented_products,
uniq(array_agg(product WHERE own)) AS owned_products
...

How can I achieve this? (I'm using Postgres 8.3)

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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Server/Data Migration Advice
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: Philosophical question