Error: syntax error at or near "$1" with super simple query
See original GitHub issueany query using .query(string, [value...], fn)
gives me this error, even with the appropriate number of values, did the api change or something? Even simple stuff like:
client.query('create user $1 with password \'Something1\'', ['tobi'], function(err){
if (err) throw err;
console.log('created');
});
I’m probably doing something obvious wrong 😄
Issue Analytics
- State:
- Created 10 years ago
- Comments:19 (13 by maintainers)
Top Results From Across the Web
Getting 'error: syntax error at or near...' in Postgresql insert query
But I'm kind of stuck at the most basic insert query which is throwing an error. I have three tables, posts , authors...
Read more >SQL Error: "Syntax error at or near:" - Looker Community
This SQL error generally means that somewhere in the query, there is invalid syntax. Some common examples: ... In some circumstances, the database ......
Read more >syntax error at or near "AS" [closed] - DBA Stack Exchange
I have a program that takes in one or more than one table names, from a list stored in a reference table and...
Read more >Postgre SQL errors – common codes and messages - Paessler
Here you'll find a list of the most common PostgreSQL errors and proven quick fix solutions: PostgreSQL error “Syntax error at or near...
Read more >MySQL 1064 Error: You have an error in your SQL syntax
One of the most common causes for the 1064 error is when a SQL statement uses a mistyped command. This is very easy...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@visionmedia It’s always fun the first time you realize PostgreSQL server doesn’t accept parameters in certain places where you’d love to have them be used. Most commands don’t accept parameters and a few places in queries you think it would be nice to use them they aren’t accepted. 😦
The good news is there are manual escaping helpers already built into node-postgres as well for the times when you want to insert user created or untrusted content into a part of a query or command where parameters aren’t accepted.
https://github.com/brianc/node-postgres/blob/master/lib/client.js#L228 https://github.com/brianc/node-postgres/blob/master/lib/client.js#L247
I apologize these aren’t better documented.
If you’re using the native bindings they actually use the escape written into
libpq
. If you’re using the pure JavaScript client the escape is as close to a direct port of thelibpq
escape functions as possible.https://github.com/segmentio/pg-escape should be sufficient 😄