Prevent inserting document without rows - Mailing list pgsql-general

From Andrus
Subject Prevent inserting document without rows
Date
Msg-id ddstca$nm$1@news.hub.org
Whole thread Raw
Responses Re: Prevent inserting document without rows  (Matt Miller <mattm@epx.com>)
List pgsql-general
I have tables for invoice headers and rows:

CREATE TABLE invoiceheader ( id SERIAL PRIMARY KEY, .... );

CREATE TABLE invoicerow ( id SERIAL PRIMARY KEY,
idheader INTEGER NOT NULL REFERENCES invoiceheader ON DELETE CASCADE ON
UPDATE CASCADE,
 ....
 );

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 ?

Andrus.



pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Cascades Failing in 8.0.x
Next
From: Tom Lane
Date:
Subject: Re: Cascades Failing