Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 3CC162E2D4A for ; Wed, 5 Mar 2008 16:03:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 81322-02 for ; Wed, 5 Mar 2008 16:03:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from glacier.frostconsultingllc.com (glacier.frostconsultingllc.com [69.36.227.170]) by postgresql.org (Postfix) with ESMTP id 67C132E0F8F for ; Wed, 5 Mar 2008 16:03:08 -0400 (AST) Received: from adsl-69-226-223-193.dsl.pltn13.pacbell.net ([69.226.223.193]:35588 helo=discord.home.frostconsultingllc.com) by glacier.frostconsultingllc.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1JWzpR-0000Tu-Ls; Wed, 05 Mar 2008 12:03:06 -0800 Received: from localhost (discord.home.frostconsultingllc.com [127.0.0.1]) by discord.home.frostconsultingllc.com (8.14.2/8.14.1) with ESMTP id m25K33I4015345 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 5 Mar 2008 12:03:04 -0800 Date: Wed, 5 Mar 2008 12:03:03 -0800 (PST) From: Jeff Frost X-X-Sender: jeff@discord.home.frostconsultingllc.com To: Osvaldo Rosario Kussama cc: pgsql-sql@postgresql.org Subject: Re: finding columns that have three or fewer distinct characters In-Reply-To: <47CEEAA3.3040004@gmail.com> Message-ID: References: <47CEEAA3.3040004@gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-SA-Exim-Connect-IP: 69.226.223.193 X-SA-Exim-Mail-From: jeff@glacier.frostconsultingllc.com X-SA-Exim-Scanned: No (on glacier.frostconsultingllc.com); SAEximRunCond expanded to false X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/20 X-Sequence-Number: 30348 On Wed, 5 Mar 2008, Osvaldo Rosario Kussama wrote: > Jeff Frost escreveu: >> I've got an interesting one...I'm trying to find columns that have three or >> fewer distinct characters (for example, "aaaaaaaaaa"). Wondering if I need >> to write a function or if someone has an idea how to do it with built in >> functions and/or pattern matching? >> >> I think the thing to do would be to lowercase everything, then remove all >> duplicate chars and spaces, then use length() on that, but it's not obvious >> to me how I might remove the duplicate chars with the pattern matching >> support in the docs. >> > > Try: > SELECT > array_to_string(array( > SELECT DISTINCT lower(substr('aabbcdddef AB',i,1)) > FROM generate_series(1,length('aabbcdddef AB')) > s(i)) > , ''); > Osvaldo, that appears to work perfectly! Thank you much! -- Jeff Frost, Owner Frost Consulting, LLC http://www.frostconsultingllc.com/ Phone: 650-780-7908 FAX: 650-649-1954