错误:查询没有结果数据的目的地

时间:2017-09-07 07:33:57

标签: postgresql postgresql-9.6

我正在尝试创建一个函数。但是得到这个错误"查询没有结果数据的目的地"在获取数据时。 我无法继续前进。任何人请分享您的想法。

这是我的功能

Create or replace FUNCTION app_user_filter_users (
 p_curUserId numeric(19,0),
 p_curApplicationTypeId numeric(19,0),
 p_page integer,
 p_listingsPerPage integer,
 p_isGlobalFilter boolean,
 p_firstNameFilter varchar(255),
 p_lastNameFilter varchar(255),
 p_emailFilter varChar(255),
 p_localeId numeric(19, 0),
 p_enabledFilter varChar(255),
 OUT p_filteredFrom integer,
 p_sort varchar(50),
 p_order varchar(10),
p_globalFilter varchar(255) = NULL) RETURNS integer
AS $$

DECLARE v_corporate boolean;
DECLARE v_enabledFilterBit boolean;
BEGIN
 create TEMP table v_sitesUserIsUserManagerFor(id numeric(19,0));
 p_globalFilter := NULLIF(p_globalFilter, '');
 p_firstNameFilter := NULLIF(p_firstNameFilter, '');
 p_lastNameFilter := NULLIF(p_lastNameFilter, '');
 p_emailFilter := NULLIF(p_emailFilter, '');
 p_localeId := NULLIF(p_localeId, -1);
 v_enabledFilterBit := case when p_enabledFilter = 'both' then null when p_enabledFilter = 'true' then 1 else 0 end;
 select corporate into v_corporate from application_type apty where apty.id = p_curApplicationTypeId;
 if v_corporate <> true
  then
  insert into v_sitesUserIsUserManagerFor select aur.facility_id from app_user_role aur join app_role ar on ar.id = aur.role_id where ar.user_management = 1 and aur.user_id=p_curUserId;
  end if;
     select cast(ceiling(cast(total_count as float) / p_listingsPerPage) as integer) as total_pages,* from (
 select count(*) over() as total_count,(select string_agg(apt.name,',') from application_type apt where exists(select * from app_user_role aur, app_role ar
   where ar.application_type_id=apt.id and aur.role_id=ar.id and aur.user_id = au.id)) as user_portals , au.id, au.first_name, au.last_name, au.email,l.name as locale, 
au.enabled from app_user au join locale l on l.id = au.locale_id where au.deleted != true
   and (v_corporate = true or (exists (select * from app_user_role aur where aur.user_id = au.id and exists (select 1 from v_sitesUserIsUserManagerFor suium where suium.id = aur.facility_id))))

   and (v_corporate = true or not exists (select * from app_user_role aur,app_role ar,application_type apt where aur.user_id = au.id and ar.id=aur.role_id and apt.corporate=true and ar.application_type_id=apt.id))
   and (
    (p_isGlobalFilter = true and (p_globalFilter is null or au.first_name like '%'||p_globalFilter||'%' 
          or au.last_name like '%' || p_globalFilter || '%' 
          or au.email like '%' || p_globalFilter || '%'))
    or (p_isGlobalFilter <> true and (p_firstNameFilter is null or au.first_name like '%'||p_firstNameFilter||'%') 
          and (p_lastNameFilter is null or au.last_name like '%' || p_lastNameFilter || '%' )
          and (p_emailFilter is null or au.email like '%' || p_emailFilter || '%')
          and (v_enabledFilterBit is null or au.enabled = v_enabledFilterBit))
   )
   AND au.locale_id = CASE WHEN p_localeId > 0 THEN p_localeId ELSE au.locale_id END


 ) x
 Order by CASE WHEN p_sort = 'id' AND p_order = 'ASC' THEN id END,
      CASE WHEN p_sort = 'id' AND p_order = 'DESC'THEN id END DESC,
      CASE WHEN p_sort = 'first_name' AND p_order = 'ASC' THEN first_name END,
      CASE WHEN p_sort = 'first_name' AND p_order = 'DESC'THEN first_name END DESC,
      CASE WHEN p_sort = 'last_name' AND p_order = 'ASC' THEN last_name END,
      CASE WHEN p_sort = 'last_name' AND p_order = 'DESC'THEN last_name END DESC,
      CASE WHEN p_sort = 'email' AND p_order = 'ASC' THEN email END,
      CASE WHEN p_sort = 'email' AND p_order = 'DESC'THEN email END DESC,
      CASE WHEN p_sort = 'locale' AND p_order = 'ASC' THEN locale END,
      CASE WHEN p_sort = 'locale' AND p_order = 'DESC'THEN locale END DESC,
      CASE WHEN p_sort = 'enabled' AND p_order = 'ASC' THEN enabled END,
      CASE WHEN p_sort = 'enabled' AND p_order = 'DESC'THEN enabled END DESC,
      CASE WHEN p_sort = 'user_portals' AND p_order = 'ASC' THEN user_portals END,
      CASE WHEN p_sort = 'user_portals' AND p_order = 'DESC'THEN user_portals END DESC
  OFFSET ((p_page-1) * p_listingsPerPage) rows 
  fetch next (p_listingsPerPage) rows only;
  EXECUTE (select count(*) from app_user where deleted <> true) INTO p_filteredFrom;
END
$$ LANGUAGE plpgsql;

我收到错误

  

错误:查询没有结果数据的目的地   提示:如果要放弃SELECT的结果,请改用PERFORM。   语境:PL / pgSQL函数app_user_filter_users(数字,数字,整数,整数,布尔值,字符   变化,字符变化,字符变化,数字,字符   变化,字符变化,字符变化,字符变化)第18行   在SQL语句

调用功能

SELECT public.app_user_filter_users(
 cast(6 as numeric),cast(9 as numeric),1,100,true,
    cast('' as varchar),cast('' as varchar),cast('' as varchar),
    cast(-1 as numeric),cast('both' as varchar),cast('user_portals' as varchar),
    cast('DESC' as varchar),cast('' as varchar)
)

0 个答案:

没有答案