From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Dara Unglaube <dara(at)glifwc(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Constraint allowing value up to 2 times but no more than 2 times |
Date: | 2015-10-12 18:51:38 |
Message-ID: | 561C013A.3090609@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Israel Brewster | 2015-10-12 19:05:21 | Re: Pattern match against array elements? |
Previous Message | Tom Lane | 2015-10-12 18:39:38 | Re: Pattern match against array elements? |