Re: Prevent inserting document without rows - Mailing list pgsql-general

From Matt Miller
Subject Re: Prevent inserting document without rows
Date
Msg-id 1124203598.3714.6.camel@dbamm01-linux
Whole thread Raw
In response to Prevent inserting document without rows  ("Andrus" <eetasoft@online.ee>)
List 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.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Cascades Failing
Next
From: Oluwatope Akinniyi
Date:
Subject: Re: ~/pgpass