Answer the question
In order to leave comments, you need to log in
How to write a stored function in PostgreSQL to check if the Login/Password pair matches?
Good day!
There is a long PostgreSQL table - sp_users
it has fields: sp_login and sp_pass how to
write a stored function like this
using PL/pgSQL or SQL :
CREATE FUNCTION
AS 'function body'
LANGUAGE plpgsql;
And returning the result 1=is_matched_pair; 2=no_match_pair Many thanks
in advance!
Ps I am very beginner, if possible with comments...
Answer the question
In order to leave comments, you need to log in
CREATE FUNCTION check_login_and_password(
_login character varying,
_password character varying
)
RETURNS boolean AS
$$
SELECT EXISTS(SELECT * FROM table_name WHERE login = _login OR password = _password);
$$
LANGUAGE sql;
CREATE FUNCTION check_login_and_password(
_login character varying,
_password character varying
)
RETURNS bigint AS
$$
SELECT count(*) FROM table_name WHERE login = _login OR password = _password;
$$
LANGUAGE sql;
Decided!
The following construction helped:
CREATE FUNCTION check_login_and_password(input_login CHARACTER VARYING, input_pass CHARACTER VARYING) RETURNS boolean AS
$$
SELECT EXISTS(SELECT * FROM sp_users WHERE "public".sp_users.p_login = input_login AND "public".sp_users.p_pass = input_pass );
$$
LANGUAGE sql;
In the request we pass:
'Login', 'Password'
If the answer is correct, it returns: t (true), if it is not true: f (false).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question