我花了半天的时间在Google上搜索,但是找不到任何使用pg gem(PostgreSQL Ruby Gem)的预处理INSERT语句的示例。
我尝试了以下代码(在查看gem文档后):
def test2
conn = PG.connect( dbname: 'db1' )
conn.prepare("statement1", 'INSERT INTO table1 (id, name, profile) VALUES (?, ?, ?)')
end
但是我遇到了以下错误:
pgtest.rb:19:in `prepare': ERROR: syntax error at or near "," (PG::Error)
LINE 1: INSERT INTO table1 (id, name, profile) VALUES (?, ?, ?)
^
from pgtest.rb:19:in `test2'
from pgtest.rb:25:in `<main>'
ERROR: ... (PG::Error)
表示错误来自于pg
而不是 Ruby。 - mu is too short