pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Mike Field <mike@fieldco.com>
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Multiple values for a field
Date: Sun, 15 Aug 1999 16:26:31 +0300
Message-ID: <l03130307b3dc6e665034@[147.233.159.109]> (raw)
In-Reply-To: <008701bee59e$0e951f80$0200a8c0@mike>

At 18:11 +0300 on 13/08/1999, Mike Field wrote:


> Do  you see any problem if I put the actual names of the authors,  comma
> separated, in the author field (for example:  Mike Field, Tom  Lane, ZZ Top)?
> I would do the same for my six fields which may have multiple  values
> (author, region, subject, related_projects, doc_type, translations) I  have
> about 550 documents to put into the database.

Repeating groups are harder to update. What if you found out that you made
a spelling mistake in some region, and you have to go through the entire
table, find it in each of the strings, and replace with the correct
version. What if you wanted to drop an author? You have to select it, fix
and update. Too much work.

> I know using text  fields would take up more space relative to just using a
> number to refer to  the author... but using a number makes me perform more
> loops and thus, more  processing time.

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.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





view thread (3+ messages)  latest in thread

Message-ID: <l03130307b3dc6e665034@[147.233.159.109]>
Permalink:  ../l03130307b3dc6e665034@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03130307b3dc6e665034@[147.233.159.109]

 · 

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: herouth@oumail.openu.ac.il, mike@fieldco.com
  Subject: Re: [SQL] Multiple values for a field
  In-Reply-To: <l03130307b3dc6e665034@[147.233.159.109]>
  References: <008701bee59e$0e951f80$0200a8c0@mike> <l03130307b3dc6e665034@[147.233.159.109]>

* 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