title: PostgreSQL: How to implement minimum cardinality?
body: <p>As answered in this question: <a href="https://stackoverflow.com/questions/3135206/cardinality-in-postgresql">Cardinality in PostgreSQL</a>, cardinality is enfforced using <a href="http://www.postgresql.org/docs/9.1/static/ddl-constraints.html" rel="nofollow noreferrer">constraints</a>.</p>
  
  <p>Cardinality rules define the allowable counts of the relationships – one-to-many, many-to-many, etc. Many-to-many is achieved using join-tables and one-to-many using FOREIGN KEY.</p>
  
  <p>But how can one implement one-to-one_or_many (one-to-1+) relationship. Which is same as to ask: How can I enforce minimum cardinality in PostgreSQL?</p>
  
  <p>A practical situation would be where one needs to store say address (or telephone number) which MUST be provided (but can be more that one) by the person (say user or customer).</p>
  
  <p>Edit:</p>
  
  <p>The above mentioned situation is a special case (with cardinality one) of a general problem. The general problem being: How to enforce cardinality of arbitrary number?</p>
  
  <p>As <a href="https://stackoverflow.com/questions/9249660/postgresql-how-to-implement-minimum-cardinality/9251536#9251536">answered by jug</a> a <em>non-null</em> FOREIGN KEY reference can be used as a work-around, if minimum-cardinality is one. It will also provide an additional feature to select default among many.</p>
  
  <p>But consider another situation of relationship between <strong>team of <a href="http://en.wikipedia.org/wiki/Cricket" rel="nofollow noreferrer">Cricket</a></strong> and its <strong>players</strong>. Every team MUST have a MINIMUM of 11 players to qualify as a team. Here the minimum cardinality is eleven (11).</p>
  
  <p>Similary, a relation between a <strong>course</strong> and a <strong>student</strong> in a school, where every student MUST enroll in AT-LEAST 5 courses and every course MUST have a MINIMUM of 10 students.</p>