Re: Regular expression in an if-statement will not work

Поиск
Список
Период
Сортировка
От Szymon Guz
Тема Re: Regular expression in an if-statement will not work
Дата
Msg-id AANLkTi=R+Z7T_hT54Q2JQybp_mRe4iMV1Bid+jsiJ4ux@mail.gmail.com
обсуждение исходный текст
Ответ на Regular expression in an if-statement will not work  (Ungermann Carsten <carsten.ungermann@ib-ungermann.de>)
Ответы Re: Regular expression in an if-statement will not work  (Ungermann Carsten <carsten.ungermann@ib-ungermann.de>)
Список pgsql-general


On 9 September 2010 12:55, Ungermann Carsten <carsten.ungermann@ib-ungermann.de> wrote:
Dear postgres list,

I need to verify the value of a column by a regular expression in an if-statement before insert or update. It should be a one to three digit value. I wrote a trigger and a trigger function. In the trigger function I want to use the following if-statement to verify the value:

IF new.value !~ E'^\d{1,3}$' THEN RAISE EXCEPTION '...some text...'; END IF;

It will not work! Why?


How about this:  

IF new.value !~ E'^\\d{1,3}$' THEN


Or if you only want to check the 3digit value, without any trigger, IMHO this is much simpler:

alter table x add constraint check_is_3_digit check ( value ~ E'^\\d{3}$' );

regards
Szymon Guz

В списке pgsql-general по дате отправления:

Предыдущее
От: Phui Hock
Дата:
Сообщение: How to inherit search_path from template
Следующее
От: "tamanna madaan"
Дата:
Сообщение: Re: error while autovacuuming