pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Martin Dolog <dolog@mcprogress.com>
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] select ... from ... where ... ~* 'C++'
Date: Mon, 6 Sep 1999 18:59:13 +0300
Message-ID: <l03130308b3f993f5266f@[147.233.159.109]> (raw)
In-Reply-To: <37D12DB8.F94227A3@mcprogress.com>

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





view thread (3+ messages)

Message-ID: <l03130308b3f993f5266f@[147.233.159.109]>
Permalink:  ../l03130308b3f993f5266f@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03130308b3f993f5266f@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: herouth@oumail.openu.ac.il, dolog@mcprogress.com
  Subject: Re: [SQL] select ... from ... where ... ~* 'C++'
  In-Reply-To: <l03130308b3f993f5266f@[147.233.159.109]>
  References: <37D12DB8.F94227A3@mcprogress.com> <l03130308b3f993f5266f@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox