-- 総タイトル数を取得し更新する関数
-- DROP FUNCTION f_upd_alltitlenum ();

CREATE OR REPLACE FUNCTION f_upd_alltitlenum() RETURNS integer AS $$
DECLARE
    _count  integer;
BEGIN

    -- 総タイトル数
    SELECT INTO _count COUNT(*)
      FROM t_item_basic_attr b
           INNER JOIN t_item_web_attr w
                   ON b.itemcd = w.itemcd
                  AND w.delflg IS FALSE
                  AND w.releasedate <= CURRENT_DATE
     WHERE b.delflg IS FALSE;

    UPDATE t_systeminfo SET alltitlenum = _count
     WHERE validflg IS TRUE;
--    RAISE NOTICE 'AllTitleNum =  % ', _count;

    RETURN 1;
END;
$$ LANGUAGE plpgsql;

