Re: Checking for a number - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: Checking for a number
Date
Msg-id 2CC541EC-CFBC-40ED-B0BB-967E517B1B5F@seespotcode.net
Whole thread Raw
In response to Re: Checking for a number  (Richard Broersma Jr <rabroersma@yahoo.com>)
List pgsql-general
On Jun 27, 2007, at 16:17 , Richard Broersma Jr wrote:

>
> --- Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.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



pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: autovacumm not working ?
Next
From: "Danyelle Gragsone"
Date:
Subject: Re: postgres and webmin