0

This query:

client.query({
  text: "SELECT * FROM users WHERE provider = ? AND remote_id = ?",
  values: [JSONuser.provider, JSONuser.remote_id]
}, 
function(err, result) { 
  ... 
})

Fails with syntax error at or near "AND".

I'm unable to figure out why. Been programming all day. I think it's simple and I'm just tired.

Edit: Using https://github.com/brianc/node-postgres

3
  • Are you sure your db library supports prepared statements? Commented Jan 9, 2012 at 5:42
  • I wonder why using JSON to feed query to sql server. (Well I may not be aware of that thing though). If the query runs in postgre's query editor, then the problem is with the JSON library you are using. Also replace AND by && and try again. But what I think is an error with quotes. Because it is a SYNTAX ERROR. Sometimes a small thing might take entire day :) Commented Jan 9, 2012 at 5:51
  • I think Samuel's answer got it. I was using ? when I should be using $1, $2, .... Will verify tomorrow. I'm using github.com/brianc/node-postgres which does support prepared statements. Commented Jan 9, 2012 at 6:27

1 Answer 1

3

Which library are you using? I assumed it's Javascript and node.js. According to the docs(https://github.com/brianc/node-postgres/blob/master/README.md) It seems that you should use $1, $2 for bind variables instead of ?

Sign up to request clarification or add additional context in comments.

2 Comments

Any idea what the proper syntax equivalent of SELECT * FROM users WHERE id IN $1 would be, where $1 is an array of values? pastie.org/3177014 gives an error like array must start with { =^] thx
@JordanFeldstein it's probably too late, but using Array.join() in some form will help. Looking here could also be helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.