I'm trying to determine whether a user already exists in my database. I know one way to do this is by running:
SELECT * FROM users WHERE email = $1
and checking if the number of rows is greater than 0 or now. However, I know that a more efficient way to run this command is by using the "EXISTS" keyword because it doesn't need to run through all the rows in the database. However, running
EXISTS (SELECT 1 FROM users WHERE email = $1)
yields
error: syntax error at or near "EXISTS"
I've also tried simply running
SELECT 1 FROM users WHERE email = $1
as this should have the same efficiency optimizations but it doesn't output any row data.
I'm using the "pg" driver. Any help is greatly appreciated. Thank you in advance!