joelc
joelc

Reputation: 2761

PostgreSQL Dollar quoting and SELECT LIKE

Is it possible to use dollar-quoted strings within a SELECT ... LIKE?

i.e.

SELECT "firstName", "lastName" FROM person WHERE "firstName" LIKE '%$xx$j$xx$'

or

SELECT * FROM person WHERE "firstName" LIKE $xx$j$xx$

or

SELECT * FROM person WHERE "firstName" LIKE $xx$j$xx$%;

The first returns no rows, because I have no names that start with $xx$j$xx$. The second returns no rows. The third returns a syntax error at the semicolon (due to the hanging %)

Upvotes: 0

Views: 175

Answers (1)

user330315
user330315

Reputation:

The LIKE wildcard needs to be part of the string, not after the string:

SELECT * FROM person WHERE "firstName" LIKE $xx$j%$xx$;

or simpler

SELECT * FROM person WHERE "firstName" LIKE 'j%';

Upvotes: 1

Related Questions