1
votes

I keep getting the "SELECT query has no destination for result data" error upon calling this test procedure. What am I doing wrong? I did try adding the RETURN() command prior to SELECT statement but that didn't work either.

CREATE OR REPLACE PROCEDURE SchemaName.SP_Testing_Creating_Procedure (OUT ColumnName VARCHAR(9)) 
AS $$  
BEGIN   
 SELECT TOP 10 ColumnName FROM SchemaName.TableName where ColumnName is not null;     
END;
$$
LANGUAGE plpgsql; 

CALL SchemaName.SP_Testing_Creating_Procedure();
2
Your procedure is running a SELECT command. What do you want to do with the results of that query?John Rotenstein

2 Answers

0
votes

As John mentioned you need to put the result into OUT column, examples of using IN, OUT and INOUT parameters you can find here

But if you need to return a few rows as a result, you have to use refcursor as it's described here

CREATE OR REPLACE PROCEDURE SchemaName.SP_Testing_Creating_Procedure (INOUT result refcursor)
AS $$
BEGIN
    OPEN result FOR
    SELECT TOP 10 ColumnName
    FROM SchemaName.TableName
    WHERE ColumnName IS NOT null;
END;
$$
LANGUAGE plpgsql;

Then you can call the stored procedure in a transaction

BEGIN;
CALL logs.SP_Testing_Creating_Procedure('mycursor');
FETCH ALL FROM mycursor;
COMMIT;

another option is temp table which is also described in the above doc

0
votes

Your procedure is running a SELECT command, but it is not doing anything with the results.

If your intention was to return a result set, you will need to put data in the OUT column.

See: Returning a result set - Amazon Redshift