pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim Ballard <jballard@netezza.com>
To: Jeff Eckermann <jeckermann@verio.net>
To: 'Dirk Lutzebaeck' <lutzeb@aeccom.com>
To: Michael Fork <mfork@toledolink.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: RE: counting distinct rows on more than one column
Date: Wed, 28 Mar 2001 17:27:09 -0500
Message-ID: <01b001c0b7d6$3fccbac0$8300a8c0@planet> (raw)
References: <08CD1781F85AD4118E0800A0C9B8580B0949E1@NEZU>

If the fields are fixed length character type, then the simpler
concatenation should work.

Actually, the requirement is only that all but the final field be fixed
length.

And if they aren't fixed length, you can cast them to be such, as long as
you know the maximum length of the string values, as in the following where
that maximum is 20 and we are looking at 3 fields:

select count(distinct (cast(field1 as char(20)) || cast(field2 as char(20))
|| field3)) from ...

Jim Ballard

----- Original Message -----
From: "Jeff Eckermann" <jeckermann@verio.net>
To: "'Dirk Lutzebaeck'" <lutzeb@aeccom.com>; "Michael Fork"
<mfork@toledolink.com>
Cc: <pgsql-sql@postgresql.org>
Sent: Wednesday, March 28, 2001 3:43 PM
Subject: [SQL] RE: counting distinct rows on more than one column


> I don't think this will necessarily work:
>
> field1 | field2
> aa     |  ab
> a       |  aab
>
> These are two distinct rows, so should be counted as two.
> The proposed method would count them as one.
> You can get around this problem by doing:
> count (distinct (a || x || b))
> where x is some character not found in your data.
>
> > -----Original Message-----
> > From: Dirk Lutzebaeck [SMTP:lutzeb@aeccom.com]
> > Sent: Wednesday, March 28, 2001 1:32 PM
> > To: Michael Fork
> > Cc: pgsql-sql@postgresql.org
> > Subject: Re: counting distinct rows on more than one column
> >
> > Michael Fork writes:
> >  > In 7.0.3, I believe the following would work:
> >  >
> >  > SELECT count(distinct(a || b)) FROM t;
> >
> > Great, this works! I don't quite get it why...
> >
> > Dirk
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>




view thread (8+ messages)

Message-ID: <01b001c0b7d6$3fccbac0$8300a8c0@planet>
Permalink:  ../01b001c0b7d6$3fccbac0$8300a8c0@planet/
Also on:    postgresql.org/message-id/01b001c0b7d6$3fccbac0$8300a8c0@planet

 · 

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: jballard@netezza.com, jeckermann@verio.net, lutzeb@aeccom.com, mfork@toledolink.com
  Subject: Re: counting distinct rows on more than one column
  In-Reply-To: <01b001c0b7d6$3fccbac0$8300a8c0@planet>
  References: <08CD1781F85AD4118E0800A0C9B8580B0949E1@NEZU> <01b001c0b7d6$3fccbac0$8300a8c0@planet>

* 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