Re: error: there is no parameter $1 - Mailing list pgsql-novice

From David Johnston
Subject Re: error: there is no parameter $1
Date
Msg-id 1381794713450-5774559.post@n5.nabble.com
Whole thread Raw
In response to error: there is no parameter $1  (Kinnard Hockenhull <kinnard@bitbox.mx>)
List pgsql-novice
Kinnard Hockenhull wrote
> I get "error: there is no parameter $1" when I try to run this code using
> the node-postgres <https://github.com/brianc/node-postgres> client:
>
> client = pg.connect(connectionString, function(err, client, done){
>     if(err) console.log(err);
>     client.query('INSERT INTO causes (cause_name, goal, organization,
> sponsor, submitter) VALUES ($1,$2,$3,$4,$5)', r, function(err){
>

This a node usage issue, not PostgreSQL.  That said you seem to be wanting
to use a prepared statement yet the syntax you show is a direct query.  In a
direct/literal query parameters (whether they be of the "?" or "$#" form)
are not allowed/understood.  Where in the code provided do you even attempt
to assign values to ${1-5}?

You either need to replace "${1-5}" with actual data or figure out how to
execute prepared queries in node.  The later is recommended since it is the
more secure way of doing things.

<goes looking at node-postgres>

Supposedly the "r" variable holds the array of five values you want to map
onto ${1-5}.  You do not show where "r" gets defined so maybe it is
undefined and thus you are not actually mapping values?

David J.



--
View this message in context:
http://postgresql.1045698.n5.nabble.com/error-there-is-no-parameter-1-tp5774552p5774559.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


pgsql-novice by date:

Previous
From: Kinnard Hockenhull
Date:
Subject: error: there is no parameter $1
Next
From: Madhavan
Date:
Subject: how to handle Pagination >