Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare field with value and return bool

I'm trying move hash cheking from server app to PostgreSQL. In other words I'm need calling a query to PGSQL, which compare string from query with string from field and return result of equal comparison as bool, but I don't know how do this without procedures on clear SQL.

upd: I have table users with field password(currently text, in the future - bytea). I want write sometihng like

select * from values ('WrittenPassword' = users.password) where username = 'someuser' ,

which must return true or false as result of equal comparison.

like image 552
Arman Hayots Avatar asked Jun 10 '12 22:06

Arman Hayots


1 Answers

You can use a CASE statement to return certain values based on a condition:

SELECT 
    (CASE WHEN password = 'WrittenPassword' THEN 1 ELSE 0 END) AS is_equal
FROM
    users
WHERE
    username = 'someuser'
like image 169
Zane Bien Avatar answered Oct 20 '22 18:10

Zane Bien