From: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
---|---|
To: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
Cc: | Osvaldo Rosario Kussama <osvaldo_kussama(at)yahoo(dot)com(dot)br>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Checking for a number |
Date: | 2007-06-27 21:59:51 |
Message-ID: | 2CC541EC-CFBC-40ED-B0BB-967E517B1B5F@seespotcode.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Jun 27, 2007, at 16:17 , Richard Broersma Jr wrote:
>
> --- Osvaldo Rosario Kussama <osvaldo_kussama(at)yahoo(dot)com(dot)br> wrote:
>> Try:
>> SELECT your_field ~ '.*[[:digit:]]{2}$';
>
> This could be simplified a little. :o)
>
> WHERE your_field ~ '\\d{2}$';
Using dollar-quotes means not having to escape your \d (which I
always find a bit of a hassle):
WHERE your_field ~ $re$\d{2}$$re$;
It's important to remember to use a tagged dollar quote (e.g., $re$)
if you're using $ as an anchor.
And with standard_conforming_strings on you don't even need to use
dollar-quotes:
test=# show standard_conforming_strings;
standard_conforming_strings
-----------------------------
on
(1 row)
test=# select 'foo33' ~ '\d{2}$';
?column?
----------
t
(1 row)
Dollar-quoting gets you around having to worry about what
standard_conforming_strings is set to, though.
Michael Glaesemann
grzm seespotcode net
From | Date | Subject | |
---|---|---|---|
Next Message | Danyelle Gragsone | 2007-06-27 22:13:01 | Re: postgres and webmin |
Previous Message | Alvaro Herrera | 2007-06-27 21:50:40 | Re: autovacumm not working ? |