Prevent inserting document without rows

From: "Andrus" <eetasoft(at)online(dot)ee>
To: pgsql-general(at)postgresql(dot)org
Subject: Prevent inserting document without rows
Date: 2005-08-16 14:31:24
Message-ID: ddstca$nm$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-08-16 14:34:10 Re: Cascades Failing
Previous Message Richard Huxton 2005-08-16 14:23:15 Re: Cascades Failing in 8.0.x