如何从postgres中的返回类型获取行数?

时间:2018-09-27 12:00:32

标签: postgresql count

我有一个返回表(我的客户类型)的函数。

如何获取返回对象的行数?

CREATE TYPE observer_holder AS ("CustomerName" TEXT,"CustomerFamily" TEXT)


CREATE OR REPLACE FUNCTION getItem(i_callStateText TEXT, i_maxText TEXT)
  RETURNS SETOF observer_holder
  LANGUAGE plpgsql

AS $$
declare
  sendOffset INTEGER;
  fetchRecord RECORD;
  result observer_holder;
  runQuery2 BOOLEAN := lower(trim(both ' ' from i_callStateText)) ='notnull' AND (position('::tsrange' in i_maxText) < 1);

  query1 TEXT := '...';
  query2 TEXT := '...';

BEGIN

  FOR fetchRecord IN EXECUTE CASE WHEN runQuery2 THEN query2 ELSE query1 END LOOP

   result."CustomerFamily" := customerRecord.family;
    result."CustomerName" := customerRecord.name;
    .
    .
    .

    RETURN next result;
  END LOOP;

  -- my question  , how get result count?
  RAISE notice 'row count: %', length(result::observer_holder);   >>  Exception
  RETURN;
END; $$;

我需要结果行计数。请帮助我。

0 个答案:

没有答案