Re: Constraint allowing value up to 2 times but no more than 2 times - Mailing list pgsql-general

From Jim Nasby
Subject Re: Constraint allowing value up to 2 times but no more than 2 times
Date
Msg-id 561C013A.3090609@BlueTreble.com
Whole thread Raw
In response to Constraint allowing value up to 2 times but no more than 2 times  (Dara Unglaube <dara@glifwc.org>)
List pgsql-general
On 10/12/15 1:41 PM, Dara Unglaube wrote:
> I created a view with the column of interest and a column of the count.
> How do I do a check constraint on a view or do it all at once as a
> subquery? Could you provide an example of how to create?

Please don't top-post. And do include the mailing list so others can learn.

The constraint would go on the table, not the view. The column would
need to not be a count, but a 'record number' or something similar. So
you'd have one record with 'record_number=1' and the second with
'record_number=2'.

CREATE TABLE ...(
   ...
   , record_number smallint NOT NULL CONSTRAINT
record_number_must_be_1_or_2 CHECK( record_number BETWEEN 1 AND 2 )
);
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Pattern match against array elements?
Next
From: Israel Brewster
Date:
Subject: Re: Pattern match against array elements?