0

I'm doing an app with express in node. I thought about different DBMS before coming up with the idea of using PostgreSQL (I haven't got any NoSQL experience) but it's bugging me out due to some unexpected errors.

I'm trying to check if a user exist when he logs, but the Select statement doesn't work, don't know why:

var query = client.query('SELECT "name" FROM "User" WHERE "pass" = $1',  [req.body.password]);
console.log(query.toString());
query.on('row', function(row) {
    console.log('user "%s"', row.name);
});

After this the initial page should render (that actually works). I'm using the node-postgres driver, by the way.

If I put something like client.query('SELECT * FROM "User"'); the database works perfectly (and I don't need that behaviour either). I've read about the PostgreSQL identifier problems, but nevertheless it keeps happening.

5
  • You should put the variable in single quotes. Commented Mar 7, 2013 at 21:51
  • @Jakub, putting in single quotes var query = client.query("SELECT 'name' FROM 'User' WHERE 'pass' = $1", [req.body.password]); gives me a syntax error in 'User', don't know why. @mu, the docs of the driver state how prepared statements (excuse the repetition) work.
    – jontxu
    Commented Mar 7, 2013 at 21:56
  • name tables must be in double quotes, strings in single quotes. So you should escape the quote. You could also do double dollar quote (sqlfiddle.com/#!1/6ccc5/1108). Commented Mar 7, 2013 at 22:03
  • If your identifiers are all legal, lower-case names, you don't need any quotes around them. Double quotes are only required for otherwise illegal (or not all lower-case) names. I don't see the error message you get in your question. Where is it? Commented Mar 7, 2013 at 22:05
  • The error is error: relation "User" does not exist. It does exist, though.
    – jontxu
    Commented Mar 8, 2013 at 20:58

1 Answer 1

0

Okay, turns out user table exists, and the table I created is case sensitive. It works know.

I tried select * from user on psql and it returned the current user. Tried select * from "User" and turned out I was wrong. Funny thing.

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.