简体   繁体   中英

AMAZON 500310: Invalid operation: syntax error at or near " Drop"

I followed https://dwgeek.com/redshift-stored-procedure-return-result-set-working-example.html/ step of creating a stored procedure using a temporary table but facing the error above.

CREATE OR REPLACE PROCEDURE sample_return_table(tmp_table INOUT varchar(256)) 
AS '
  DECLARE
    row record;
  BEGIN
   EXECUTE ' DROP table if exists ' || tmp_table;
   EXECUTE ' CREATE temp TABLE  ' || tmp_table ||  ' AS SELECT DISTINCT table_schema FROM information_schema.tables ';
  END;
'
LANGUAGE plpgsql;

Error:

[Amazon](500310) Invalid operation: syntax error at or near "DROP" 
Position: 132; [SQL State=42601, DB Errorcode=500310]
1 statement failed.

May I know what is the issue ?

Here is a sample Stored Procedure from Overview of stored procedures in Amazon Redshift :

CREATE OR REPLACE PROCEDURE test_sp1(f1 int, f2 varchar)
AS $$
BEGIN
  RAISE INFO 'f1 = %, f2 = %', f1, f2;
END;
$$ LANGUAGE plpgsql;

Notice that use of $$ to identify the content of the procedure, whereas your code is using ' .

The problem with using ' is that it is also being used inside the procedure (eg just before DROP ) and is therefore confusing Redshift.

Try changing to an unused sequence (such as $$ ) to avoid this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM