| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | Her Goo <gu_he(at)msn(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: sql: "LIKE" problem |
| Date: | 2005-03-14 08:16:07 |
| Message-ID: | 42354847.9070403@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Richard Huxton | 2005-03-14 08:20:42 | Re: finding schema of table that called a trigger |
| Previous Message | Miroslav Šulc | 2005-03-14 08:15:14 | Re: lower and unicode |