Escaping an underscore in LIKE - Mailing list pgsql-general

From Richard Huxton
Subject Escaping an underscore in LIKE
Date
Msg-id 20010307.21155000@client.archonet.com
Whole thread Raw
List pgsql-general
Am I doing something stupid trying to escape an underscore in LIKE?


richardh=> select * from foo;
  a
-----
 a_c
 a_d
 abc
(3 rows)

richardh=> select * from foo where a like 'a_c';
  a
-----
 a_c
 abc
(2 rows)

richardh=> select * from foo where a like 'a\_c';
  a
-----
 a_c
 abc
(2 rows)

richardh=> select * from foo where a like 'a\_c' escape '\\';
  a
-----
 a_c
 abc
(2 rows)

richardh=> select * from foo where a like 'ax_c' escape 'x';
  a
-----
 a_c
(1 row)

- Richard Huxton

pgsql-general by date:

Previous
From: "Simon Crute"
Date:
Subject: Re: How robust is postgresql ?
Next
From: ryan@paymentalliance.net
Date:
Subject: Postgresql 7.1 Beta 5, Postmaster dead