Convert Rows or Arrays to Comma Delimited String

There are times when you need to take multiple rows and convert the data into a single comma separated text string. Here are some examples.

Sub-Select

select bp.value ,
 (
     select array_to_string(array_agg(r.documentno),',') from r_request r where r.c_bpartner_id = bp.c_bpartner_id and r.processed='N'
 )
 from c_bpartner bp

Notice how the above subselect uses two key functions:

Entire Query

select array_to_string(array(
select concat('<a href="',chuboe_googlemap_location(chuboe_address_bploc(x.c_bpartner_location_id, ' ')),'" target="_blank">',chuboe_address_bploc(x.c_bpartner_location_id, ' '),'</a>') from c_bpartner_location x where c_bpartner_id = @C_BPartner_ID@
),'<br>')

Notice how the above select uses two key functions: