pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: jdmorgan <jdmorgan@unca.edu>
To: pgsql-sql@postgresql.org
Subject: array_agg order by
Date: Mon, 27 Feb 2012 22:50:12 -0500
Message-ID: <4F4C4EF4.4000006@gmail.com> (raw)

Hello,

I am using a array_agg to get a subset of data to use in a 
query.However, I can't figure out how to get the data returned in the 
array_agg function to sort with an order by function.Any help would be 
appreciated.Here is my query as it is now.I am using postgresql 8:

select pestproxshapes.pt_id, pestproxshapes.gid, 
array_to_string(array_agg(coalesce(pestproxdata.agent || ' | Closest 
Agent (km): ' || round(pestproxdata.metric1,2) || ' | Acres: ' || 
round(pestproxdata.metric2, 2) || ' | count: ' || pestproxdata.count || 
' | yr: ' || pestproxdata.year || ' | prob: ' || 
round(pestproxdata.prob,2) || ' | host: ' || pestproxdata.host, 'no 
agents reported within 75km')), '\n') as AGENTS from pestproxshapes left 
outer join pestproxdata on pestproxshapes.pt_id=pestproxdata.pt_id where 
pestproxshapes.pt_id = 8089 group by pestproxshapes.pt_id, 
pestproxshapes.gid;

Thanks,

Derek

view thread (2+ messages)  latest in thread

Message-ID: <4F4C4EF4.4000006@gmail.com>
Permalink:  ../4F4C4EF4.4000006@gmail.com/
Also on:    postgresql.org/message-id/4F4C4EF4.4000006@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jdmorgan@unca.edu
  Subject: Re: array_agg order by
  In-Reply-To: <4F4C4EF4.4000006@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox