Check constraint and at least two rows

From: Dane Foster <studdugie(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Check constraint and at least two rows
Date: 2015-11-03 23:55:51
Message-ID: CA+WxinJxoeDTLxgCZeA75LGCADg4aaKmchxkHAmsUJr7pHJnJQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I have a design/modelling puzzle/problem. I'm trying to model a series of
events. So I have two tables w/ a parent child relationship. The child
table has the rule/constraint/etc that for every row in the parent table
there must be at least 2 rows in the child because a series must have at
least 2 events to be a series.

Now the SQL for the constraint is straight-forward and easy to write. What
I haven't figure out yet is where to put it because a straight forward
table constraint won't work because it's checked on every INSERT which
means it will be tripped on the first row inserted. A trigger doesn't seem
to fit the bill either.

Ideas?

Thanks,

Dane

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2015-11-04 00:09:11 Re: Check constraint and at least two rows
Previous Message Leonardo M. Ramé 2015-11-03 23:55:01 MinGW-W64 compile error