Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql escape single quote in where clause [duplicate]

Tags:

sql

postgresql

so I am trying to run a script like this one:

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

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

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

Anyone knows how I can run a query like this one?

like image 657
Eugen Avatar asked Aug 01 '16 14:08

Eugen


People also ask

How do I replace a single quote in PostgreSQL?

Postgres replace singlequote with two single quotes In Postgresql, REPLACE function can be used to replace the single quote with two single quotes in the string. Syntax: REPLACE(source, old_data, new_data ); Where the source is string or data where we want to replace.

How do you escape quotes in PostgreSQL?

Normally single and double quotes are commonly used with any text data in PostgreSQL. To ignore or escape the single quote is a common requirement of all database developers. By using double quotes and backslash we can avoid the complexity of single quotes as well as it is easy to read and maintain.

How do you escape a single quote in a double quote?

You need to escape single quote when the literal is enclosed in single code using the backslash(\) or need to escape double quotes when the literal is enclosed in a double code using a backslash(\).

How do I escape double quotes in PostgreSQL?

Quotes and double quotes should be escaped using \.


1 Answers

You can escape single quotes when you double them. For example:

= 'john''s' 
like image 106
manuzi1 Avatar answered Sep 20 '22 18:09

manuzi1