pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ray Plante <rplante@ncsa.uiuc.edu>
To: pgsql-sql@postgresql.org
Subject: GROUP BY: v6.1 vs. v6.5.2
Date: Mon, 31 Jan 2000 17:03:38 -0600
Message-ID: <389614CA.965430FF@ncsa.uiuc.edu> (raw)

Hi,

I have a question regarding a change in the way GROUP BY has work
between PostgreSQL versions 6.1 and 6.5.2.  The latter version's man
page for SELECT says, 

  "When GROUP BY is present, it is not valid to refer to ungrouped
   columns except within aggregate functions, since there would be 
   more than one possible value to return for an ungrouped column."

This seems sensible.  However, version 6.1 did not have this
restriction; for any ungrouped function not within an aggregate, the
first matching value was returned.  In effect, a default aggregate was
applied.  Unfortunately, my application took advantage of this
behavior.  My basic question is, what's the easiest way to duplicate
this behavior using v6.5.2?

Here's a simplified run down of what I am doing, starting with the
tables I'm operating on:

  create table projects (
    yr int,
    nimg int,
    authors text[]
  );
  create table docs (
    yr int,
    im int,
    title text
  );
  select p.yr,p.nimg,p.authors,d.im,d.title
    into table joint
    from projects p,docs d
    where p.yr=d.yr;

Here's the sort of search I would using the older PG version:

  select yr,nimg,authors from joint 
    where title~'word'
    group by yr;

There is a one-to-many mapping between projects and documents.  Thus,
the attributes from the projects table will be duplicated in joint for
each matching record from docs.  What I want from the above select are
the projects that contain any doc with a title matching 'word'; but, I
only want one record per project.  

The simple solution should be including the other project attributes
list in the select clause in my group-by clause:

  select yr,nimg,authors from joint
    where title~'word'
    group by yr,nimg,authors;

The problem is that authors is a text array.  When I do this, I get the
error message:

ERROR:  Unable to identify a binary operator '<' for types _text and
_text

I've also tried creating an aggregate function for text arrays that just
returns the last value encountered; however, the array nature gave me
trouble.  (I'll save the details for another posting if necessary.)

many thanks,
Ray Plante



view thread (3+ messages)  latest in thread

Message-ID: <389614CA.965430FF@ncsa.uiuc.edu>
Permalink:  ../389614CA.965430FF@ncsa.uiuc.edu/
Also on:    postgresql.org/message-id/389614CA.965430FF@ncsa.uiuc.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: rplante@ncsa.uiuc.edu
  Subject: Re: GROUP BY: v6.1 vs. v6.5.2
  In-Reply-To: <389614CA.965430FF@ncsa.uiuc.edu>
  References: <389614CA.965430FF@ncsa.uiuc.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