Postgresql escapes single quotes in where where

so I'm trying to run a script like this:

select id from owner where owner.name = "john's" 

and I get this error: ERROR: column "john's" does not exist .

Also I tried like this: where owner.name = 'john\'s' , but it does not work

Does anyone know how I can run such a query?

+19
source share
2 answers

You can avoid single quotes when you double them. For instance:

 = 'john''s' 
+26
source

Try this

 select id from owner where owner.name = (E'john\'s')::text 

Update: we can avoid most characters using this statement

select the identifier from the owner, where owner.name = (E'john * Your character you want to escape * s') :: text

+5
source

All Articles