Delete all records NOT referenced by Foreign Keys

Поиск
Список
Период
Сортировка
От D. Dante Lorenso
Тема Delete all records NOT referenced by Foreign Keys
Дата
Msg-id 3FDACBBF.8050901@lorenso.com
обсуждение исходный текст
Ответы Re: Delete all records NOT referenced by Foreign Keys
Re: Delete all records NOT referenced by Foreign Keys
Список pgsql-general
I'd like to run a clean up command on my tables to
eliminate rows that I'm no longer using in the database.

I want to do something like this:

    DELETE FROM tablename
    WHERE IS_REFERENCED_BY_FOREIGN_KEY IS FALSE;

Does anyone know how something like this could be done
in PostgreSQL?  I know I can search all the tables that
I know refer to this table and see if my primary key
exists, but I want a solution that does not require me to
rewrite my code every time a new foreign key constraint
is added to the database.

There must be a way to ask PostgreSQL for a reference count
on a given row or something.

Thanks,

Dante

---------
D. Dante Lorenso
dante@lorenso.com






В списке pgsql-general по дате отправления:

Предыдущее
От: "Matthew T. O'Connor"
Дата:
Сообщение: Re: Windows Version of PostgreSQL
Следующее
От: "Keith C. Perry"
Дата:
Сообщение: Re: tablespaces in 7.5?