As in PostgreSQL to write a stored function matching pair of Username/Password?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
9 views
Good day!
PostgreSQL has a long table - sp_users
it has fields: sp_login and sp_pass
how to use PL/pgSQL or SQL
write a stored function:

CREATE FUNCTION
AS 'function body'
LANGUAGE plpgsql;

And returns the result 1=estimatedtime; 2=nesovpadeniye

In advance huge human thanks!

PS. I'm a very beginner, if you can review...
by | 9 views

2 Answers

0 like 0 dislike
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;

Or if you really need the number as the result:
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;
by
0 like 0 dislike
Solved!
Helped the following design:

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;

Per request pass:
'Login', 'Password'

If the answer is correct returns: t (true) if not true: f (false).
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked May 21, 2019 by nursultanya
110,608 questions
257,186 answers
0 comments
35,405 users