Escaping an underscore in LIKE

From: Richard Huxton <richardh(at)archonet(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Escaping an underscore in LIKE
Date: 2001-03-07 21:15:50
Message-ID: 20010307.21155000@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?

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

Browse pgsql-general by date

  From Date Subject
Next Message dev 2001-03-07 21:37:08 Re: Update through views?
Previous Message Simon Crute 2001-03-07 21:14:05 Re: How robust is postgresql ?