Escaping underscores in LIKE

From: dev(at)archonet(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Escaping underscores in LIKE
Date: 2001-03-08 09:20:40
Message-ID: 20010308.9204000@client.archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Am I doing something stupid trying to escape an underscore in LIKE?
Version 7.1b3

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Trewern, Ben 2001-03-08 10:24:52 RE: Data types?
Previous Message dev 2001-03-08 09:17:33 CONTRIB: int8 sequence simulator