Search Postgresql Archives

Re: Checking for a number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Jun 27, 2007, at 16:17 , Richard Broersma Jr wrote:


--- Osvaldo Rosario Kussama <osvaldo_kussama@xxxxxxxxxxxx> 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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux