Search code examples
node.jspostgresqlpg

Problems with Node.js and postgresql


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.


Solution

  • 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.