This article is half-done without your Comment! *** Please share your thoughts via Comment ***
The single quote and apostrophe (s) are commonly used with any text data.
To escape or ignore the single quote is a standard requirement for all database developers.
In this post, I am sharing solution for PostgreSQL Database Server.
PostgreSQL has two options to escape single quote.
You can replace single quote to double single quote like (”) and the other is you can use (E’\’) to escape single quote.
First, Create a sample table:
1 2 3 4 5 |
CREATE TABLE tbl_SingleQuoted ( ID INTEGER ,TextData TEXT ); |
Insert some sample data with single quote using both (”) and (\’):
1 2 3 4 5 |
INSERT INTO tbl_SingleQuoted VALUES (1,E'Anvesh\'s dbrnd.com') ,(2,E'Database\'s Properties') ,(3,'The dbrnd Blog''s Reviews'); |
To SELECT all data which has ( ‘s ):
1 2 3 |
SELECT * FROM tbl_SingleQuoted WHERE TextData LIKE E'%\'s%'; |
The Result:
1 2 3 4 5 |
id | textdata ----+-------------------------- 1 | Anvesh's dbrnd.com 2 | Database's Properties 3 | The dbrnd Blog's Reviews |
Leave a Reply