pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Osvaldo Rosario Kussama <osvaldo.kussama@gmail.com>
To: Jeff Frost <jeff@frostconsultingllc.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: finding columns that have three or fewer distinct characters
Date: Wed, 05 Mar 2008 15:46:59 -0300
Message-ID: <47CEEAA3.3040004@gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0803050912570.4804@discord.home.frostconsultingllc.com>
References: <Pine.LNX.4.64.0803050912570.4804@discord.home.frostconsultingllc.com>

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



view thread (4+ messages)  latest in thread

Message-ID: <47CEEAA3.3040004@gmail.com>
Permalink:  ../47CEEAA3.3040004@gmail.com/
Also on:    postgresql.org/message-id/47CEEAA3.3040004@gmail.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: osvaldo.kussama@gmail.com, jeff@frostconsultingllc.com
  Subject: Re: finding columns that have three or fewer distinct characters
  In-Reply-To: <47CEEAA3.3040004@gmail.com>

* 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