pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Her Goo <gu_he@msn.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: sql: "LIKE" problem
Date: Mon, 14 Mar 2005 08:16:07 +0000
Message-ID: <42354847.9070403@archonet.com> (raw)
In-Reply-To: <BAY11-DAV4899E308FCFAA7E626003F85560@phx.gbl>
References: <BAY11-DAV4899E308FCFAA7E626003F85560@phx.gbl>

Her Goo wrote:
> I am using "postgresql-7.3.2-1" now!
> 
> I met a problem when using "LIKE" in "WHERE" clause.
> For example, a table named "t_test", and its data looks like below:
> 
> # SELECT * FROM t_test;
>  id | c_name 
> ----+--------
>   1 | abc\
>   2 | abc\de
> (2 rows)

> # SELECT * FROM t_test WHERE c_name LIKE 'abc\d%';
>  id | c_name 
> ----+--------
> (0 rows)
> 
> I don't know why the result is "0 rows"(why not is "1 rows"), 
> And I have trid "LIKE 'abc\\d%'", the result is also "0 rows".

You'll need to escape the backslash twice. Once for the SQL-level
parsing and once for the LIKE pattern-matching itself.

SELECT * FROM t_test WHERE c_name LIKE 'abc\\\\d%';

--
  Richard Huxton
  Archonet Ltd



view thread (3+ messages)

Message-ID: <42354847.9070403@archonet.com>
Permalink:  ../42354847.9070403@archonet.com/
Also on:    postgresql.org/message-id/42354847.9070403@archonet.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, gu_he@msn.com
  Subject: Re: sql: "LIKE" problem
  In-Reply-To: <42354847.9070403@archonet.com>

* 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