Re: CONSTRAINT on ARRAY ELEMENTS - Mailing list pgsql-docs

From Dmitriy Igrishin
Subject Re: CONSTRAINT on ARRAY ELEMENTS
Date
Msg-id CAAfz9KMYyOX=5bneYu5DJJNNWWTkAMZb3i0tVbUW-oKkYRM82w@mail.gmail.com
Whole thread Raw
In response to CONSTRAINT on ARRAY ELEMENTS  (Nikolaos Ikonomopoulos <ikonomn@hotmail.com>)
List pgsql-docs
Hey Nikolaos,

2012/11/3 Nikolaos Ikonomopoulos <ikonomn@hotmail.com>

CREATE TABLE employ_presence
(
  p_id character(6) not null,
  p_month character(3) NOT NULL,
  statuscode integer array[7],
  CONSTRAINT unq_employ_presence UNIQUE (p_id, p_month),
  CONSTRAINT chk_employ_month CHECK (p_month = ANY (ARRAY['Jan'::bpchar, 'Feb'::bpchar, 'Mar'::bpchar, 'Apr'::bpchar, 'May'::bpchar, 'Jun'::bpchar, 'Jul'::bpchar, 'Aug'::bpchar, 'Sep'::bpchar, 'Oct'::bpchar, 'Nov'::bpchar, 'Dec'::bpchar]))
);



How can add a CONSTRAINT on statuscode array elements to accept values between 0 to 5

0 = Employ present
1 = Employ Patient
2 = day off
3 = Regular vacation
4 = external job assignment
5 = external job assignment abroad
6 to 9  for future use

Thanks.

I recommend you to create the table "status" and create
foreign key constraint in the table "employ_presence"
instead. This will do exactly what are you want.

--
// Dmitriy.


pgsql-docs by date:

Previous
From: Nikolaos Ikonomopoulos
Date:
Subject: CONSTRAINT on ARRAY ELEMENTS
Next
From: Jeff Davis
Date:
Subject: Re: CONSTRAINT on ARRAY ELEMENTS