You can use escape_string
to correctly avoid single quotes:
db = PG.connect(...) db.exec("insert into t (...) values ('#{db.escape_string(str)}', ...)")
or use prepare
and exec_prepared
to work with a prepared statement:
db.prepare('ins', 'insert into t (...) values ($1, ...)') db.exec_prepared('ins', [str, ...])
source share