Re: Prevent inserting document without rows

From: Matt Miller <mattm(at)epx(dot)com>
To: Andrus <eetasoft(at)online(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Prevent inserting document without rows
Date: 2005-08-16 14:46:38
Message-ID: 1124203598.3714.6.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2005-08-16 at 17:31 +0300, Andrus wrote:
> Each invoice must have at leat one row.
>
> I want that transaction commit fails if invoice header is inserted
> without
> any row in invoice rows table.
>
> How to prevent inserting invoice headers without rows ?

You could have a NOT NULL foreign key in the header table referencing
the detail table. You then have declarative integrity guaranteeing that
at least one detail entry exists for each header entry.

How your system populates this column is another question. In this case
maybe some client-side logic would be cleaner than a trigger-based
solution.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-08-16 15:00:28 Re: [GENERAL] Cascades Failing
Previous Message Tom Lane 2005-08-16 14:34:10 Re: Cascades Failing