I have this code :
require 'pg'
a = ["bla","foo","bar","test","wow"]
begin
con = PG.connect :dbname => 'base', :user => 'thatsme'
a.map do |e|
con.prepare('statement1','INSERT INTO keywords (keyword, created_at, updated_at) VALUES ($1, $2, $3)')
con.exec_params('statement1', ["#{e}", '2017-01-01 07:29:33.096192', '2017-01-01 07:29:33.096192' ])
end
This causes an error, which is
ERROR: syntax error at or near "statement1"
I don't get it. I'm missing something...
con.exec_params('statement1', ["#{e}", ...ERROR: syntax error at or near "statement1""#{e}"are concerning and look like Cargo Cult Programming. If you want to be sureeis a string, use `e.to_s, though the driver often does this conversion automatically. Additionally, instead of banging against the low-level driver, try and use something with a bit of abstraction, like Sequel.eis a string then"#{e}"is just noise that distracts from what you're trying to do.