Reputation: 876
I Work with Postgresql and I want to drop Table if exists .My code is
execute 'drop table if exists production.'|| layer_name || '' into result_var;
exception
when others then
execute 'insert into production.'|| layer_name || ' select * from staging.'|| layer_name ;
return 1;
but table if not exists thows exeption .I do not want to trow exeption
Can anybody help me?
Upvotes: 0
Views: 1318
Reputation: 61516
DROP TABLE
does not return any row, so the INTO
clause must not be used.
Also, don't use WHEN OTHERS
in an exception block that eats any error whatever it is.
It's frustrating both for debugging and troubleshooting problems later when the code is deployed.
If it wasn't for this clause, you'd had the error message saying why it doesn't work.
Upvotes: 3