Thread: SIMILAR TO

SIMILAR TO

From
Rommel the iCeMAn
Date:
Hi guys,

I use the following code to detect alphanumeric strings:

IF _my_variable SIMILAR TO '^[a-zA-Z0-9]+$' THEN
        // do stuff here
END IF;

In pg8.4 this worked perfectly. I upgraded to pg9.0 and it no longer
works. From the release notes it appears that the behavior of SIMILAR
TO has changed in pg9.0. My question is, how do I modify my code so
that it works in 9.0?

Thanks in advance.
Rommel.


Re: SIMILAR TO

From
Tom Lane
Date:
Rommel the iCeMAn <icecrew@gmail.com> writes:
> I use the following code to detect alphanumeric strings:

> IF _my_variable SIMILAR TO '^[a-zA-Z0-9]+$' THEN
> � � � � // do stuff here
> END IF;

> In pg8.4 this worked perfectly. I upgraded to pg9.0 and it no longer
> works. From the release notes it appears that the behavior of SIMILAR
> TO has changed in pg9.0. My question is, how do I modify my code so
> that it works in 9.0?

Drop the ^ and $; they are incorrect for SIMILAR TO.
        regards, tom lane


Re: SIMILAR TO

From
Rommel the iCeMAn
Date:
Thank you very much. I figured it was something simple but I am not
proficient at regular expressions. Thanks again.

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Saturday, October 16, 2010 10:30 AM
To: Rommel the iCeMAn
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] SIMILAR TO

Rommel the iCeMAn <icecrew@gmail.com> writes:
> I use the following code to detect alphanumeric strings:

> IF _my_variable SIMILAR TO '^[a-zA-Z0-9]+$' THEN
>         // do stuff here
> END IF;

> In pg8.4 this worked perfectly. I upgraded to pg9.0 and it no longer
> works. From the release notes it appears that the behavior of SIMILAR
> TO has changed in pg9.0. My question is, how do I modify my code so
> that it works in 9.0?

Drop the ^ and $; they are incorrect for SIMILAR TO.
        regards, tom lane