Re: how to disable all pkey/fkey constraints globally

Поиск
Список
Период
Сортировка
От Joe Abbate
Тема Re: how to disable all pkey/fkey constraints globally
Дата
Msg-id 4EA0959B.5070505@freedomcircle.com
обсуждение исходный текст
Ответ на Re: how to disable all pkey/fkey constraints globally  ("J.V." <jvsrvcs@gmail.com>)
Список pgsql-general
On 10/20/2011 05:10 PM, J.V. wrote:
> Is there a simpler way than this to query the database for meta-data and
> get the constraint definitions?
>
> If I have the constraint name (which I do), I could store the constraint
> definition to a file or database table and recreate them if I could get
> the definition.
>
> This seems like a very simple thing to do, but nowhere can I find the
> meta-data I would need to first save the constraint, to later re-create it.

The metadata is all in the PostgreSQL catalogs.  One could write
PL/pgSQL (or other PL) functions to select all the info from the
catalogs into a simple text (SQL statement) format (e.g., ALTER TABLE
tbl ADD CONSTRAINT ...), and also to generate or execute the disabling
(ALTER TABLE tbl DROP CONSTRAINT ...) statements.

You may think it's very simple, but I can assure you that adding or
dropping constraints is not so easy because the ADDs and DROPs have to
be issued in an order that takes into account inter-table/constraint
dependencies (including, in the general case, constraints that are
inherited between tables).

Joe

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

Предыдущее
От: Raymond O'Donnell
Дата:
Сообщение: Re: plpgsql at what point does the knowledge of the query come in?
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: plpgsql at what point does the knowledge of the query come in?