Re: Checking for a number
| От | Michael Glaesemann | 
|---|---|
| Тема | Re: Checking for a number | 
| Дата | |
| Msg-id | 2CC541EC-CFBC-40ED-B0BB-967E517B1B5F@seespotcode.net обсуждение исходный текст | 
| Ответ на | Re: Checking for a number (Richard Broersma Jr <rabroersma@yahoo.com>) | 
| Список | 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 по дате отправления: