How fetch multiple rows into one text-field?
How fetch multiple rows into one text-field?
От:
Andreas <maps.on@gmx.net>
Дата:
Hi, how can I fetch multiple rows into one text-field? I need the contents of some log-infos condensed into a single text to show in a report. There is a log with a single record per event. The log is like this (log_id, case_id, log_date, log_category, log_notes) I need a date-ordered list of log-date, -category, -notes of all log-events of the same case-id like log_date || ' ' || log_category || ' : ' || log_nots e.g. 20.07.2009 Category 17 : utterly noteworthy notes 21.07.2009 Category 42 : lots more 22.07.2009 Category 17 : still more drivel The report consists of a couple of case-infos and should look like case_id, case_name, case_all_log_events Is there a way to do this? regards andreas
Re: How fetch multiple rows into one text-field?
От:
Joshua Tolley <eggyknap@gmail.com>
Дата:
On Fri, Jul 31, 2009 at 10:09:46PM +0200, Andreas wrote: > Hi, > > how can I fetch multiple rows into one text-field? > I need the contents of some log-infos condensed into a single text to > show in a report. It sounds like you might want something like this: SELECT ... array_to_string(array_accum(log_notes, '')) FROM... You might need to add array_accum manually; before 8.4 it wasn't built in. See http://www.postgresql.org/docs/8.3/static/xaggr.html -- Joshua Tolley / eggyknap End Point Corporation http://www.endpoint.com