Trabla: FUNCTION template - return ASSOCIATED array ( one row with predefined fields )
Solving:
DROP FUNCTION my_test_function();
DROP TYPE my_type;
-- Create custom type - assoc array model
CREATE TYPE my_type AS (
id bigint
, title text
);
-- Create function to return custom type
CREATE OR REPLACE FUNCTION my_test_function ()
RETURNS my_type AS
$BODY$
DECLARE
result my_type;
BEGIN
result.id = 1;
result.title = 'Simple title';
RETURN result;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
;
-- Example of function call
SELECT * FROM my_test_function();
--Output result
|id|title |
|1 |'Simple title'|
No comments:
Post a Comment