I have an insert routine that not accept single quote in the inserted text:
single'quote
The query:
INSERT INTO posts (post_subject,post_desc,post_type,post_status) VALUES ('single'quote','test',0,0) RETURNING post_id
The Go code:
func Insert(query string) int {
id := 0
err := db.QueryRow(query).Scan(&id)
if err != nil {
log.Fatal(err)
}
return id
}
This crashes Go and I get an answer:
pq: syntax error at or near "quote"
My question is if there is any way but “replaceall” for every and each field? Sometimes you want a single quote in your text. Is there a global setting “allow singlequotes”? I know I can use ` (backticks), but is there no other way?