skip to Main Content

I am trying to search a column in PostgreSQL that has values containing single quote characters.
Here’s the string I’d like to search and fail to do properly:

activities,'L','D'

I’ve tried using LIKE with both $$ and ” to escape the single quotes but im not able to properly write down the query.

Here is my where clause:

where 1=1 and table.column LIKE '%activities,''L'',''D''%'

thank you in advance

2

Answers


  1. Chosen as BEST ANSWER

    I want to thank everyone for their input! It turned out the issue was not withe the SQL code itself, but rather with the fact the text was not consistent within the text column itself.


  2. You can use single quotes to escape the single quotes, as follows:

    SELECT * FROM test WHERE table.column LIKE 'ctivities,''L'',''D''';
    

    Yoy can find a working example here: https://www.db-fiddle.com/f/hHCyXADG7dPGgsdf6kVf9d/8

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search