Re: Constraint allowing value up to 2 times but no more than 2 times

Поиск
Список
Период
Сортировка
От Jim Nasby
Тема Re: Constraint allowing value up to 2 times but no more than 2 times
Дата
Msg-id 561C013A.3090609@BlueTreble.com
обсуждение исходный текст
Ответ на Constraint allowing value up to 2 times but no more than 2 times  (Dara Unglaube <dara@glifwc.org>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Pattern match against array elements?
Следующее
От: Israel Brewster
Дата:
Сообщение: Re: Pattern match against array elements?