How to make case sensitive query with nodejs + pg
I want to select column content == 'a@gmail.com',
but it seems become select column == 'a@gmail.com'?
[error: column "a@gmail.com" does not exist]
code
var userEmail = 'a@gmail.com';
var query = 'SELECT EXISTS(SELECT * FROM "User" WHERE "Email" = "'+userEmail+'")';
dbClient.query(query, function(error, result) {
...
This doesn't have anything to do with case. The problem is that you're putting the email address in double-quotes, and in (most varieties of) SQL double-quotes indicate a column name or table name. That's why the error message says column "a@gmail.com" does not exist
.
Use single-quotes around values:
var userEmail = 'a@gmail.com';
var query = 'SELECT EXISTS(SELECT * FROM "User" WHERE "Email" = \'' + userEmail + '\')';
Ideally, though, you should just use parameter binding so you don't have to worry about quoting values at all. When you use string concatenation to build SQL queries you very often open yourself up to SQL injection attacks.