1
votes

is it possible to create a stored procedures on sql workbench that uses a redshift database ?

I tried to put in some procedure found on the internet like this one

CREATE OR REPLACE FUNCTION proc_sample RETURN INTEGER
IS
  l_result INTEGER;
BEGIN
  SELECT max(col1) INTO l_result FROM sometable;
  RETURN l_result;
END;

but I get an error the cursor is not located inside a statement

help please.

2

2 Answers

0
votes

Here is my translation of your stored procedure for Redshift:

CREATE OR REPLACE PROCEDURE proc_sample (
      l_result  OUT  INTEGER
)
LANGUAGE plpgsql
AS $$
BEGIN
  SELECT max(col1) INTO l_result FROM sometable;
END
$$;

You call this stored procedure in Redshift as follows:

BEGIN; CALL proc_sample(); END;
--  l_result
-- ----------
--        99

For more information see "Overview of stored procedures in Amazon Redshift"

0
votes

you can not use from clause in function. you have to use procedure having parameter with out clause.