Обсуждение: Select rotate in PostgreSql

Поиск
Список
Период
Сортировка

Select rotate in PostgreSql

От
Andre Lopes
Дата:
Hi all,

I don't know how to ask for this. I need to rotate a Select in
PostgreSql, just like this: http://dpaste.com/1021691/

I can achieve this easily without a procedure?

Best Regards,


Re: Select rotate in PostgreSql

От
Merlin Moncure
Дата:
On Wed, Mar 13, 2013 at 8:32 AM, Andre Lopes <lopes80andre@gmail.com> wrote:
> Hi all,
>
> I don't know how to ask for this. I need to rotate a Select in
> PostgreSql, just like this: http://dpaste.com/1021691/
>
> I can achieve this easily without a procedure?

yes: that's not rotation but simple aggregation.  look for string_agg
here: http://www.postgresql.org/docs/9.2/static/functions-aggregate.html

merlin


Re: Select rotate in PostgreSql

От
Fabrízio de Royes Mello
Дата:

On Wed, Mar 13, 2013 at 10:32 AM, Andre Lopes <lopes80andre@gmail.com> wrote:
Hi all,

I don't know how to ask for this. I need to rotate a Select in
PostgreSql, just like this: http://dpaste.com/1021691/

I can achieve this easily without a procedure?


Hi Andre,

If I understood you want to aggregate "comments" into a single line... is it? If yes then you can try this:

SELECT article_id, string_agg(comments, ' ') FROM your_table GROUP BY article_id;

Best regards,

--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
>> Blog sobre TI: http://fabriziomello.blogspot.com
>> Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
>> Twitter: http://twitter.com/fabriziomello