Обсуждение: select ... from ... where ... ~* 'C++'

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

select ... from ... where ... ~* 'C++'

От
Martin Dolog
Дата:
hi *,

PLease, how can I make case insensitive query
which work with string like 'C++' too ?

select something from something_t where some ~* 'C++'

doesn't work!
I got following error message:

"ERROR:  regcomp failed with error repetition-operator operand invalid"


I am running on Linux/Redhat6/postgresql6.5 compiled
with --enable-locale flag.


Thank you very much for help.


Martin

-- 

#md

************




Re: [SQL] select ... from ... where ... ~* 'C++'

От
"tjk@tksoft.com"
Дата:
Martin,

Try

select something from something_t where some ~* 'C[+][+]'

or rather,

select something from something_t where some like '%C++%'

Troy


>
>
> hi *,
>
> PLease, how can I make case insensitive query
> which work with string like 'C++' too ?
>
> select something from something_t where some ~* 'C++'
>
> doesn't work!
> I got following error message:
>
> "ERROR:  regcomp failed with error repetition-operator operand invalid"
>
>
> I am running on Linux/Redhat6/postgresql6.5 compiled
> with --enable-locale flag.
>
>
> Thank you very much for help.
>
>
>
>     Martin
>
> --
>
> #md
>
> ************
>
>

Re: [SQL] select ... from ... where ... ~* 'C++'

От
Herouth Maoz
Дата:
At 17:33 +0300 on 04/09/1999, Martin Dolog wrote:


> PLease, how can I make case insensitive query
> which work with string like 'C++' too ?
>
> select something from something_t where some ~* 'C++'

You should read the manual page for regex - it explains which characters
are special in a regular expression. In principle, you should add two
backslashes before each special character, like '.', '*', '+', '?', '[' etc.

SELECT something FROM something_t WHERE some ~* 'C\\+\\+';

If you are wondering why *two* backslashes... Well... If you put one
backslash, it tells postgres that the next character is to be taken
literally. Thus, if your string is 'C\+\+', it will pass 'C++' to the
regexp level, because the parsing of the string is done before passing them
to the regexp function.

Using two backslashes, the first backslash passes the second literally, so
the regexp function gets 'C\+\+'. It then knows that the pluses are not to
be considered special.

Passing a backslash, I suspect, requires writing no less than four
backslashes in the query...

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma