I'm writing a function that logs interactions with a Facebook messenger bot. Anything the user says is logged in a PostgreSQL database.
My insert statement looks like this:
INSERT INTO interactions (fbid,date,time,event) VALUES ('senderid','2018-10-
01','11:15:48','text')
Treat "senderid" as a 20-digit number and "text" as whatever the user says.
Now, the above statement works IF the text from the user contains no apostrophe characters. However, sometimes the text DOES contain apostrophes. In these cases, the insert doesn't work.
For example, if the user says "Let's chat" then my SQL looks like this:
INSERT INTO interactions (fbid,date,time,event) VALUES
('senderid','2018-10-01','11:15:19','Let's Chat!')
and I get the following error:
Query result: error: syntax error at or near "s"
I know this is because I would need to escape the apostrophe. I've tried working around this by using double quotes in my insert statement, like this:
INSERT INTO interactions (fbid,date,time,event) VALUES ("senderid","2018-09-
28","10:50:07","Let's chat")
But when I do this I get the following error:
ERROR: column "senderid" does not exist
So I have two questions:
- CAN I use double quotes in a SQL insert?
- If I CAN'T use double quotes in a SQL insert, how would I escape an apostrophe character, bearing in mind there may not always BE an apostrophe?