I want to execute following raw SQL with Korma:
k/exec-raw
["INSERT INTO events ?, VALUES ? ON CONFLICT (id) DO UPDATE SET title = EXCLUDED.title;" [keys values]]
with params equal to:
keys (str "(" (keys->str res) ")")
values (str "(" (serialize (merge res) ", ") ")" )
The both evaluate to correct strings and work in repl.
But in runtime i have following error in psql console:
ERROR: syntax error at or near "$1" at character 20
STATEMENT: INSERT INTO events $1, VALUES $2 ON CONFLICT (id) DO UPDATE SET title = EXCLUDED.title
Can't figure out what's the problem. Anybody have ever done insert with Korma?
PostgreSQL 9.5 + Korma 0.4.2
Only values can be used as parameters in a prepared statement. So to make it work:
If you want to work it like you do you have to prepare the sql string yourself and make sure you don't have an sql injection. Please see the manual