[ACCEPTED]-How to delete table *or* view from PostgreSQL database?-plpgsql
Accepted answer
DROP TABLE user_statistics;
DROP VIEW user_statistics;
complete syntax:
And if you want a complete 1 function, i tried something like this:
CREATE OR REPLACE FUNCTION delete_table_or_view(objectName varchar) RETURNS integer AS $$
DECLARE
isTable integer;
isView integer;
BEGIN
SELECT INTO isTable count(*) FROM pg_tables where tablename=objectName;
SELECT INTO isView count(*) FROM pg_views where viewname=objectName;
IF isTable = 1 THEN
execute 'DROP TABLE ' || objectName;
RETURN 1;
END IF;
IF isView = 1 THEN
execute 'DROP VIEW ' || objectName;
RETURN 2;
END IF;
RETURN 0;
END;
$$ LANGUAGE plpgsql;
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.