[postgis-users] Deleting particular tables

Nicolas Ribot nicky666 at gmail.com
Tue Nov 27 01:46:27 PST 2007


> Hello,
>
> I have a table which contains a column 'tablename'. In this column, the
> names of my geo tables are stored.
> I want do write a query which deletes all geo tables in my database which
> names don't appear in the column 'tablename' of this admin table. Has
> someone any idea?
>

Hello

If your geo tables were created with addGeometryColumns, or if you
have updated the geometry_columns metadata table, then you have the
list of all geo tables in it.
>From it, and from your custom table, you should be able to build the
list of geo tables that are not in your custom table.
I think a pl/pgsql function is the easiest way to do this: for each
geo table stored in the geometry_columns that is not in your admin
table, generate a "drop table..." statement.

If you do not use geometry_columns table (which is bad), you will have
to look at the Postgresql system tables to list all the tables having
a geometric column, then filtering out those registered in your admin
table.
(i do not remember the name of such tables, but PostgreSQL
documentation may help)

HTH
Nico