First time using pg gem to access the postgres database. I have successfully connected and can run queries using #exec , but now creating a simple query using #exec_params does not seem to replace the parameters. I.e:
get '/databases/:db/tables/:table' do |db_name, table_name| conn = connect(db_name) query_result = conn.exec_params("SELECT * FROM $1;", [table_name]) end
leads to #<PG::SyntaxError: ERROR: syntax error at or near "$1" LINE 1: SELECT * FROM $1; ^ > #<PG::SyntaxError: ERROR: syntax error at or near "$1" LINE 1: SELECT * FROM $1; ^ >
It seems like such a simple example to work with - I fundamentally misunderstand how to use this method?
source share