Re: Posix the tool to use?

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Romain Billon-Grand <rbgrbg(at)free(dot)fr>
Cc: Forum postgres debutants <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Posix the tool to use?
Date: 2012-10-07 22:07:54
Message-ID: CAK3UJREzsGPz4W6_uw7w1WvtS0-NdipVEpV3JtKiWo4nqgV0Ag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, Oct 8, 2012 at 12:39 AM, Romain Billon-Grand <rbgrbg(at)free(dot)fr> wrote:
> Good evening
> As a novice with postgres, I am not even sure to be on the good way for
> probably quite a basic query...
> I am trying to retrieve all rows where one of the text column is a code made
> of 4 letters followed by 3 numbers such as "LFFA002" or "QSZT123", and of
> course only them. Other rows from the table are empty, or containing some
> short sentences, or single letters between brackets. To heterogeneous to be
> a way to take the problem the other side (that is why I need to clean this
> ~26000 row table...). But I barely understand anything to Posix or regular
> expressions in the postgres documentation, even though I feel those could be
> the tools I need for my WHERE statement...
> Would you please tell me how to code this?

I think this POSIX regex would do the trick for matching exactly 4
letters followed by exactly 3 numbers, with nothing else at the start
or end of the string:

'^[A-Za-z]{4}[[:digit:]]{3}$'

> Or better, help me finding a
> tutorial I could understand(=dummy-adapted!!)? (Even better if it is in
> French or Spanish, far more natural than english for me!)

Section 9.7.3 of the Postgres docs is a good place to start, albeit in English:

http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP

There are many books out there which give more comprehensive
explanations of the subject, e.g. "Mastering Regular Expressions".
Also, the Postgres community has separate French and Spanish language
lists if you prefer:

http://www.postgresql.org/community/lists/

Josh

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message sravanch 2012-10-09 04:27:27 Guidance needed to be a postgreSQL DBA
Previous Message Romain Billon-Grand 2012-10-07 21:39:00 Posix the tool to use?