0

I have a string: A%A

I want to find all string same start with A%A in database.

Example:

AABCD - false
AABCE - false
AA%BC - true

I use the sql statement:

Select * from Tabel where Column like 'AA%B%'

But the result are:

AABCD
AABCE
AA%BC

Because the string include wildcard '%' and postgres select wrong.

Please suggest me a solution

Dragon
  • 95
  • 2
  • 9
  • Check this [how-to-escape-string-while-matching-pattern-in-postgresql](http://stackoverflow.com/questions/10153440/how-to-escape-string-while-matching-pattern-in-postgresql) if it helps. – NzGuy Oct 20 '16 at 07:48

1 Answers1

2

To escape the % char, use \ like this \%

UPDATE

Another approach can be achieved by using the ESCAPE keyword with empty string after it, this way you tell postgres to disable escaping, and the % becomes a normal char

select * from Table where Column like '%' ESCAPE '';
Or Duan
  • 13,142
  • 6
  • 60
  • 65