pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>
To: Herouth Maoz <herouth@oumail.openu.ac.il>
Cc: Mike Field <mike@fieldco.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Multiple values for a field
Date: Sun, 15 Aug 1999 10:36:26 -0500
Message-ID: <19990815103626.A19124@wallace.ece.rice.edu> (raw)
In-Reply-To: <l03130307b3dc6e665034@[147.233.159.109]>
References: <008701bee59e$0e951f80$0200a8c0@mike>
	<l03130307b3dc6e665034@[147.233.159.109]>

On Sun, Aug 15, 1999 at 04:26:31PM +0300, Herouth Maoz wrote:
> 
> An alternative may be to create an aggregate function that will give you
> the comma-separated list you desired upon request:
> 
> CREATE AGGREGATE textcat_all
> (
> 	basetype = text,
> 	sfunc1 = textcat,
> 	stype1 = text
> );
> 
> Then you can do something like:
> 
> SELECT da.docid, textcat_all( a.Author_name || ',' )
> FROM docs_authors da, authors a
> WHERE da.authorid = a.id
> GROUP BY da.docid;
> 
> This will return a comma-separated list of author names for each doc id,
> assuming the actual author name is in a separate table. There is an extra
> comma at the end, but I don't suppose that's too much of a problem.
> 

And can be solved as so:
SELECT da.docid, rtrim(textcat_all( a.Author_name || ',' ), ',') ...

Excellent tip, Herouth. This one goes in the 'keepers' bag.

Ross
-- 
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005



view thread (3+ messages)

Message-ID: <19990815103626.A19124@wallace.ece.rice.edu>
Permalink:  ../19990815103626.A19124@wallace.ece.rice.edu/
Also on:    postgresql.org/message-id/19990815103626.A19124@wallace.ece.rice.edu

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: reedstrm@wallace.ece.rice.edu, herouth@oumail.openu.ac.il, mike@fieldco.com
  Subject: Re: [SQL] Multiple values for a field
  In-Reply-To: <19990815103626.A19124@wallace.ece.rice.edu>
  References: <008701bee59e$0e951f80$0200a8c0@mike> <l03130307b3dc6e665034@[147.233.159.109]> <19990815103626.A19124@wallace.ece.rice.edu>

* 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