Обсуждение: trouble with regular expression

Поиск
Список
Период
Сортировка

trouble with regular expression

От
Pushker Chaubey
Дата:
Hi experts,

I have a problem regarding  regular expression.

In my database (version 8.0.2 ) I have a value stored as "([t]{0,1})^(t?)+$\"
(Please note that this value uses many characters which have special meaning in regular expression)

Earlier I had a query which used to fetch this value
SELECT "Topic" FROM "schema1"."Topics" WHERE "Topic"  similar to '\\(\\[t\\]{0,1}\\)\\^\\(t?\\)\\+\\$\\\\' ORDER BY "Topic"
This query worked fine and did return the matching value stored in database .

Later on to support, case insensitive value search, I modified the query to
SELECT "Topic" FROM "schema1"."Topics" WHERE "Topic"  ~*     '\\(\\[t\\]{0,1}\\)\\^\\(t?\\)\\+\\$\\\\' ORDER BY "Topic"

(Please note that I just replaced similar to with ~*)

The new query does not work. Please let me know where I am making a mistake.
If there are other approaches to go about case insensitive pattern matching in query, please provide pointers to that.

Thanks in advance.

Regards,
Pushker Chaubey


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy the original message all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. Please do not print this email unless it is absolutely necessary.

Re: trouble with regular expression

От
Tom Lane
Дата:
Pushker Chaubey <pchaubey@vertex.co.in> writes:
> (Please note that I just replaced similar to with ~*)

They're not the same ... SIMILAR TO is SQL-spec which is almost entirely
unlike POSIX.

You can get there using the undocumented similar_escape function:
"a SIMILAR TO b" is actually implemented as "a ~ similar_escape(b,null)",
so "a ~* similar_escape(b,null)" should do what you want.

            regards, tom lane

Re: trouble with regular expression

От
Pushker Chaubey
Дата:
Tom,
Thanks a lot! It worked.

Tom Lane wrote:
Pushker Chaubey <pchaubey@vertex.co.in> writes: 
(Please note that I just replaced similar to with ~*)   
They're not the same ... SIMILAR TO is SQL-spec which is almost entirely
unlike POSIX.

You can get there using the undocumented similar_escape function:
"a SIMILAR TO b" is actually implemented as "a ~ similar_escape(b,null)",
so "a ~* similar_escape(b,null)" should do what you want.
		regards, tom lane
 


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy the original message all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. Please do not print this email unless it is absolutely necessary.