问题
I need a command to delete a table if that exists in NETEZZA, Something like that:
drop table if exists xxx;
I have searched and tried many but it didn't work. Can you help me here?
回答1:
In netezza
you can use this syntax:
drop table table_name if exists;
回答2:
There is nothing built-in, but you can create a stored proc which uses the catalog views to check if the table exists before attempting to drop it:
create or replace procedure maybe_drop(varchar(128))
returns boolean
language nzplsql
as
begin_proc
declare
oname alias for $1;
o record;
begin
select otype into o
from (
select 'TABLE' otype from _v_table where tablename = upper(oname)
union all
select 'VIEW' otype from _v_view where viewname = upper(oname)
) x;
if found then
execute immediate 'DROP '||o.otype||' '||oname;
end if;
end;
end_proc;
来源:https://stackoverflow.com/questions/26624118/drop-if-exists-in-netezza