by 김동일 [2022.02.11 13:24:15]
CREATE OR REPLACE FUNCTION public.sp_resource_account_create(_resource_id integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$
declare
_cnt int;
_resource_id int4;
begin
select r.index_resource, r.word_index, r.resource_name from resources r where index_resource = _resource_id limit 1;
if (_resource_id is null) or (_resource_id = 0) then
return 'Not Registered Resource ID';
else
select count("userId") into _cnt
from (select u."userId" , a.index_resource as index_resource
from "user" u left outer join (select ra."userId", ra.index_resource as index_resource
from resource_account ra
where ra.index_resource = _resource_id) as a on u."userId" = a."userId") as k
where index_resource is null;
if (_cnt is null) or (_cnt = 0) then
return 'Every User Had Assigned This Asset';
else
insert into resource_account ("userId", index_resource, amount)
select k."userId",_resource_id ,0
from
(select
u."userId" as "userId" ,
a.index_resource as index_resource
from "user" u
left outer join (select ra."userId", ra.index_resource as index_resource
from resource_account ra
where ra.index_resource = _resource_id) as a
on u."userId" = a."userId") as k
where index_resource is null;
end if;
return 'user assigned';
end if;
return 'Occured Error Dont Expect';
end;$function$
;
어느 부분에서 잘못된건지 잘모르겠어서 도움요청드립니다.
SQL Error [42601]: ERROR: query has no destination for result data Hint: If you want to discard th
이 해당에러가 떠서 어느부분을 잡아야하는지 감이 안오네요 ㅠㅠ
1. _resource_id 가 두번 선언되어 있네요.
2. RETURNS integer 인데? 문자열을 리턴하네요?
1. _resource_id 가 두번 선언되어 있네요.
혹시 해당 부분이 어느부분인지 알 수 있을까요?
아 2번 문의주신 부분은 character varying 으로 변경했습니다
해결 했습니다!! 마농님이 말씀해주신 두번 선언된 부분 확인하면서 다른 부분들도 수정하여 확인했더니 되네요 ㅎㅎㅎ