I have a very simple stored procedure:
CREATE OR REPLACE PROCEDURE delivery.get_assets(IN row_limit integer)
AS $$
BEGIN
select group_id
from delivery.assets
order by id desc
limit row_limit;
END ;
$$
LANGUAGE plpgsql ;
I'm trying to run the SP using:
CALL delivery.get_assets(6)
The error I get is as follows:
ERROR: query has no destination for result data HINT: If you want to discard the results of a SELECT, use PERFORM instead. CONTEXT: PL/pgSQL function delivery.get_assets(integer) line 3 at SQL statement SQL state: 42601
I'm using PostgresQL 11.
In SQL Server all I have to do is call the SP. I read that in Postgres, you don't need a return statement as you would with functions. Any help is appreciated!
***AS PER COMMENTS BELOW, I'VE CHANGED THE SP TO A FUNCTION (Thank you JSpratt & Horse With No Name).
I'm almost there, but now when I call the function, it's returning in the following format:
How do I get this to return as a normal data set in a grid?
CREATE OR REPLACE FUNCTION delivery.get_assets(
number_rows integer)
RETURNS TABLE(assets_media_id INT, assets_person_id INT)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
BEGIN
RETURN QUERY SELECT
media_id,
person_id
FROM delivery.assets;
END; $BODY$;