1

I am in trouble that how to be inserted symbol like single quotes(any other) in postgresql database. There are many solutions from this site that i have tried but my problem is not get solved.

I have checked all the symbols as below. All symbols are inserted into database correctly. But i am getting an error while inserting only on single quotes.

i.e. ! @ # $ % ^ & * ( ) _ + - = { } [ ] | \ :  " < > ? ;  , . /  / *   - + .

Can anyone solve this issue that how to stored single quotes..? Is that problem with character varying,..? Or is their something that i have missed..? Following is my query

INSERT INTO command_tbl(sno, deviceid, command)  VALUES (111, 'c_bc0ac1fe48', 'Di1'ABC');
Ashish
  • 15
  • 1
  • 8

1 Answers1

0

The single quote is the delimiter for string values in SQL. So your query syntax is invalid. To put a single quote inside a string, you mst escape it by another single quote:

'Di1''ABC'

That's usually not a problem you face when programmatically inserting values in a database, because you should use prepared statements, with parameters, to do that, and the database driver deals with special characters for you.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255