ERROR: query has no destination for result data

谁都会走 提交于 2019-12-06 19:51:41

问题


CREATE OR REPLACE FUNCTION _chkLogin(userid varchar, pwd varchar)
RETURNS BOOLEAN AS
$BODY$
DECLARE 
 passed BOOLEAN;
BEGIN
 SELECT  (_password = $2) FROM _vRegistration WHERE _userid = $1;
 RETURN passed;
END;
$BODY$
LANGUAGE 'plpgsql';

When am executing the code above am getting the following error,

SELECT _chkLogin('username','abcd') as passed;

ERROR: query has no destination for result data

I've used perform then i get a different problem,

PERFORM _chkLogin('username','abcd');

ERROR: syntax error at or near "perform"

Suggest me what should I be doing in order to overcome this error.


回答1:


You do return passed but you never assign value to it.

And select command within the function has to have place to put data to.

So. Change your SQL to:

SELECT  (_password = $2) INTO passed FROM _vRegistration WHERE _userid = $1;

Also - since you're using names for variables (userid, pwd) use them:

SELECT  (_password = pwd) INTO passed FROM _vRegistration WHERE _userid = userid;



回答2:


Notes about assign value

(see this other question for assign value to variable at declaration section)

The language PLpgSQL syntax have many ways to say:

 Y := f(X);

The EXECUTE clause is only for "dynamic execution" (less performance),

 EXECUTE 'f(X)' INTO Y;     

Use Y := f(X); or SELECT for execute static declarations,

 SELECT f(X) INTO Y;

Use PERFORM statment when discard the results or to work with void returns:

 PERFORM f(X);     


来源:https://stackoverflow.com/questions/2085421/error-query-has-no-destination-for-result-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!