CREATE OR REPLACE FUNCTION qa_returnjson(
/*IN p_categoryid INT,
IN p_iconid INT, */
OUT dno VARCHAR,
OUT datajson JSON
) RETURNS SETOF RECORD AS
$BODY$
DECLARE
v_data JSON;
v_data2 VARCHAR :='1';
iRowCk INT := 0;
BEGIN
SELECT COUNT(category_name) INTO iRowCk
FROM category;
IF iRowCk <> 0 THEN
SELECT row_to_json(t) INTO v_data FROM(
SELECT 'True' AS "Status" ,
(
SELECT array_to_json(
ARRAY(
SELECT row_to_json (tt) FROM (
SELECT category_id AS "CateID", category_name AS "CateName",
(
SELECT array_to_json(
ARRAY(
SELECT row_to_json(ttt) FROM(
SELECT icon_id,icon_name FROM icon
) AS ttt
)
)
) AS "DatarowIcon"
FROM(
SELECT category_id,category_name FROM category WHERE category_active = TRUE ORDER BY category_id ASC
) AS x
) AS tt
)
)
) AS "Datarow"
) AS t;
RETURN QUERY SELECT v_data2 AS iData, v_data AS "DataJson";
END IF;
END;
$BODY$
LANGUAGE plpgsql;