brianc / node-postgres-docs

Documentation for node-postgres
https://node-postgres.com
MIT License
97 stars 94 forks source link

LOWER function not working with parameterized values #137

Closed jamesmart77 closed 3 years ago

jamesmart77 commented 3 years ago

Hey Brian - the PG library is fantastic!

This is a pretty basic problem, but after some research, I am still scratching my head around what's going on with the WHERE condition not being respected.

Here's the query:

    const sql = `SELECT id FROM employees WHERE LOWER(email) = LOWER($1);`;

    const { rows } = await query(sql, [email]);

The email parameter is being passed in the function, but when this executes in the app, it returns no records. But when I run the following in DBViz it does work...so it must be something with the LOWER function wrapping the $1 parameter.

DBViz query: SELECT id FROM employees WHERE LOWER(email) = LOWER('test@acme.com');

I could .toLowerCase() the email variable prior to passing it to the query params, but would love for the DB to handle all this. Any ideas?

Thanks for the help!

jamesmart77 commented 3 years ago

This was a completely dumb problem...had to take my head out of the sand. Sorry about that.