From: | Ungermann Carsten <carsten(dot)ungermann(at)ib-ungermann(dot)de> |
---|---|
To: | Szymon Guz <mabewlun(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Regular expression in an if-statement will not work |
Date: | 2010-09-09 15:36:38 |
Message-ID: | 41C785E8-C66B-4BCB-AF40-FBA97D05EF7E@ib-ungermann.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I tried it once more, now. There is no change in the behavior. I use the $$-notation to avoid double "\" and double "'". Also there is no syntax error in this statement.
The constraint is a bad option because I have to log errors when I import a csv-file.
Thanks and regards
Carsten Ungermann
Am 09.09.2010 um 15:44 schrieb Szymon Guz:
>
>
> On 9 September 2010 12:55, Ungermann Carsten <carsten(dot)ungermann(at)ib-ungermann(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Richardson | 2010-09-09 15:43:15 | Query help, please |
Previous Message | Tom Lane | 2010-09-09 15:16:36 | Re: Forcing the right queryplan |