Received: from mr01.conversent.com (smtp.oem.net [216.41.101.18]) by mail.postgresql.org (8.11.3/8.11.1) with ESMTP id f2SMS8U08218 for ; Wed, 28 Mar 2001 17:28:08 -0500 (EST) (envelope-from jballard@netezza.com) Received: from planet (host182.209-113-208.oem.net [209.113.208.182] (may be forged)) by mr01.conversent.com (8.10.2/8.10.2) with SMTP id f2SMRXc18067; Wed, 28 Mar 2001 17:27:33 -0500 (EST) Message-ID: <01b001c0b7d6$3fccbac0$8300a8c0@planet> From: "Jim Ballard" To: "Jeff Eckermann" , "'Dirk Lutzebaeck'" , "Michael Fork" Cc: References: <08CD1781F85AD4118E0800A0C9B8580B0949E1@NEZU> Subject: Re: RE: counting distinct rows on more than one column Date: Wed, 28 Mar 2001 17:27:09 -0500 Organization: Netezza Corporation MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200103/591 X-Sequence-Number: 2261 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" To: "'Dirk Lutzebaeck'" ; "Michael Fork" Cc: 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 >