I'm trying to write a query that deletes/drops a table, if another table exists:
DO
$do$
BEGIN
IF EXISTS (SELECT FROM table1) THEN
DELETE FROM table2;
END IF;
END
$do$;
but all that it is doing is deleting rows from table1 if table2 exists rather than the table itself.
Can you use a function similar to the one above or should I use drop table if exists?