Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 5E96B2E0325 for ; Wed, 5 Mar 2008 13:34:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 77790-04 for ; Wed, 5 Mar 2008 13:33:55 -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 12E222E0255 for ; Wed, 5 Mar 2008 13:33:56 -0400 (AST) Received: from adsl-69-226-223-193.dsl.pltn13.pacbell.net ([69.226.223.193]:48668 helo=discord.home.frostconsultingllc.com) by glacier.frostconsultingllc.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1JWxV5-0007tK-Cn for pgsql-sql@postgresql.org; Wed, 05 Mar 2008 09:33:55 -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 m25HXrTS005478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 5 Mar 2008 09:33:54 -0800 Date: Wed, 5 Mar 2008 09:33:53 -0800 (PST) From: Jeff Frost X-X-Sender: jeff@discord.home.frostconsultingllc.com To: pgsql-sql@postgresql.org Subject: finding columns that have three or fewer distinct characters Message-ID: 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/16 X-Sequence-Number: 30344 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. -- Jeff Frost, Owner Frost Consulting, LLC http://www.frostconsultingllc.com/ Phone: 650-780-7908 FAX: 650-649-1954