From mike@fieldco.com Fri Aug 13 15:05:56 1999 Received: from funredes.org (funredes.org [205.160.164.9]) by hub.org (8.9.3/8.9.3) with SMTP id LAA84773 for ; Fri, 13 Aug 1999 11:05:56 -0400 (EDT) (envelope-from mike@fieldco.com) Received: from mike (net0port48.tricom.net) by funredes.org (5.x/SMI-SVR4) id AA04496; Fri, 13 Aug 1999 11:08:28 -0400 Message-Id: <008701bee59e$0e951f80$0200a8c0@mike> From: "Mike Field" To: Subject: Multiple values for a field Date: Fri, 13 Aug 1999 11:11:00 -0400 Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0084_01BEE57C.869A09E0" X-Priority: 3 X-Msmail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3155.0 X-Mimeole: Produced By Microsoft MimeOLE V4.72.3155.0 This is a multi-part message in MIME format. ------=_NextPart_000_0084_01BEE57C.869A09E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi- Does anyone have any ideas on the following? In my database that categorizes research documents and publications, I = have in some cases more than one author, more than one region, subject, etc. = per document. You mentioned yesterday that the best way to handle that is = to have a table for say, authors like this: docid | authorid and have more than one row for a document if that document has more than = one author. My problem is that I'm pulling the info out of the database on the web, = and I find that I have to use a loop for the fields that have multiliple values - and since I have several of those fields, many loops starts to = bog down the processor. My objective is to try to get all the data out, for = all documents, in one single query - so that I can make a list of all the documents and their pertinent data. 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. 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. Let me know what you think. Thanks, Mike ------=_NextPart_000_0084_01BEE57C.869A09E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi-
 
Does anyone have any ideas on the following?

In my database = that=20 categorizes research documents and publications, I have
in some cases = more=20 than one author, more  than one region, subject, etc.=20 per
document.  You mentioned yesterday that the best way to = handle that=20 is to
have a table for say, authors like = this:

docid  =20 |   authorid

and have more than one row for a document = if that=20 document has more than one
author.

My problem is that I'm = pulling the=20 info out of the database on the web, and
I find that I have to use a = loop for=20 the fields that have multiliple
values - and since I have several of = those=20 fields, many loops starts to bog
down the processor.  My = objective is to=20 try to get all the data out, for all
documents, in one single query - = so that=20 I can make a list of all the
documents and their pertinent = data.

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

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

Let me know what you=20 think.
Thanks,
Mike
------=_NextPart_000_0084_01BEE57C.869A09E0-- From herouth@oumail.openu.ac.il Sun Aug 15 13:25:14 1999 Received: from mx99.openu.ac.il (arbel.openu.ac.il [147.233.32.4]) by hub.org (8.9.3/8.9.3) with ESMTP id JAA79547 for ; Sun, 15 Aug 1999 09:25:14 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from talmon.openu.ac.il (talmon.openu.ac.il [147.233.32.11]) by mx99.openu.ac.il (Postfix) with ESMTP for id 5B1764B672; Sun, 15 Aug 1999 16:25:13 +0300 (IDT) Received: from [147.233.159.109] (mac-herouth.pc.openu.ac.il) by talmon.openu.ac.il (Netscape Messaging Server 3.54) with ESMTP id AAA6568; Sun, 15 Aug 1999 16:28:49 +0300 X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <008701bee59e$0e951f80$0200a8c0@mike> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Date: Sun, 15 Aug 1999 16:26:31 +0300 To: "Mike Field" , From: Herouth Maoz Subject: Re: [SQL] Multiple values for a field Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id JAA79597 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 From reedstrm@wallace.ece.rice.edu Sun Aug 15 15:36:42 1999 Received: from wallace.ece.rice.edu (root@wallace.ece.rice.edu [128.42.12.154]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA98550 for ; Sun, 15 Aug 1999 11:36:42 -0400 (EDT) (envelope-from reedstrm@wallace.ece.rice.edu) Received: by wallace.ece.rice.edu via sendmail from stdin id (Debian Smail3.2.0.102) for pgsql-sql@postgreSQL.org; Sun, 15 Aug 1999 10:36:26 -0500 (CDT) Date: Sun, 15 Aug 1999 10:36:26 -0500 From: "Ross J. Reedstrom" To: Herouth Maoz Cc: Mike Field , pgsql-sql@postgreSQL.org Subject: Re: [SQL] Multiple values for a field Message-ID: <19990815103626.A19124@wallace.ece.rice.edu> References: <008701bee59e$0e951f80$0200a8c0@mike> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.3i In-Reply-To: ; from Herouth Maoz on Sun, Aug 15, 1999 at 04:26:31PM +0300 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., NSBRI Research Scientist/Programmer Computer and Information Technology Institute Rice University, 6100 S. Main St., Houston, TX 77005