Re: Checking Multiplicity Constraints and Retrieving

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Ledina Hido <lh1101(at)ecs(dot)soton(dot)ac(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Checking Multiplicity Constraints and Retrieving
Date: 2005-10-20 21:32:09
Message-ID: 1129843929.8300.799.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2005-10-19 at 15:25 +0100, Ledina Hido wrote:

> First of all, is there any way of limiting the number of rows in a
> table, referencing to the same element of another table? For example,
> force a manager not to have more than 10 employees under his control.
> In a way this can be seen as checking the multiplicity of the
> relation between the two tables. I know one way would be using
> triggers, but I was wondering if there was a way of specifying this
> when the table is constructed.

That's a lack of function within the SQL standard and PostgreSQL doesn't
implement that as an extension.

XML Schema allows you to define minoccurs and maxoccurs, but not the
SQL:2003 standard.

It would be very cool if it did, I grant you. You have to do this
yourself via a trigger. Just make sure you create an index on the
columns and you'll be fine - apart from the extra cost of inserting
rows, so keep maxoccurs small.

Best Regards, Simon Riggs

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-10-20 21:38:41 Re: [HACKERS] 'a' == 'a '
Previous Message Michael Glaesemann 2005-10-20 21:12:32 Re: NULL != text ?