Re: Check Constraints and pg_dump

From: Jonathan Scott <jwscott(at)vanten(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Check Constraints and pg_dump
Date: 2004-03-01 05:42:34
Message-ID: 20040301144234.554ed6a3.jwscott@vanten.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom,

I have another instance of a possible function being used as a check constraint: a function that makes sure there is one row, and only one row in a table.

At table creation, and the creation of the constraint, there are no rows in the table. So, even if the constraint is a valid one to have, it will fail.

We use check constraint functions in a few places, and they work just fine for us (minus the case of trying to restore the database from a pg_dump archive). Is it impossible to treat check constraints similar to other constraints and make them deferrable, specifically in the restoration from a pg_dump archive? Is there a specific reason check constraints are handled differently from other constraints?

Jonathan Scott

On Thu, 26 Feb 2004 08:54:59 -0500
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Jonathan Scott <jwscott(at)vanten(dot)com> writes:
> > The functions and tables create just fine, but when it gets to the
> > COPY part of the sql script, it tries to load tables in what really is
> > the wrong order. The check constraint is making sure there is a "plan"
> > before there is a "contract", yet pg_dump is trying to load the
> > contract table before there is anything in the plan table.
>
> Shouldn't you be using a foreign key for that?
>
> I don't see any reasonable way that pg_dump can be expected to
> understand that a check constraint expresses a relationship between two
> tables. The semantics of check constraints aren't right for it anyway.
>
> All else being equal, I think the tables will be loaded in OID order,
> so a possible workaround is to create the plan table first. But an
> FK seems like a better answer.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

--
Jonathan Scott, Programmer, Vanten K.K.
jwscott(at)vanten(dot)com Tel: 03-5919-0266
http://www.vanten.com Fax: 03-5919-0267

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-03-01 06:21:16 Re: [HACKERS] Collaboration Tool Proposal -- Summary to date
Previous Message Christopher Browne 2004-03-01 04:11:31 Re: User defined types -- Social Security number...