¾�ΥС�������ʸ�� �� 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9.6 | 9.5 | 9.4 | 9.3 | 9.2 | 9.1 | 9.0 | 8.4 | 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2

8.7. ���

����enum�˷�����Ū��������������줿�ͤΡ�����դ����礫��ʤ�ǡ������Ǥ��� ����ϡ�¿���Υץ�����ߥ󥰸���ˤ�����enum����Ʊ���Ǥ��� ��󷿤���Ȥ��ơ�������ġ��Υǡ����ˤĤ��ƤΥ��ơ������ͤν��礬�󤲤��ޤ���

8.7.1. ��󷿤����

��󷿤�CREATE TYPE���ޥ�ɤ���Ѥ��ƺ�������ޤ��� �ʲ�����򼨤��ޤ���

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');

�����塢¾�Υǡ������ȤۤȤ��Ʊ���褦�ˡ���󷿤�ơ��֥��ؿ�����ǻ��Ѥ��뤳�Ȥ��Ǥ��ޤ���

例 8-3. ����Ū����󷿤λ�����ˡ

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
    name text,
    current_mood mood
);
INSERT INTO person VALUES ('Moe', 'happy');
SELECT * FROM person WHERE current_mood = 'happy';
 name | current_mood 
------+--------------
 Moe  | happy
(1 row)

8.7.2. ���

�������ͤν���Ϥ��η���������������ͤ���󤷤����֤ˤʤ�ޤ��� ��󷿤��Ф��ơ����٤Ƥ���ӱ黻�Ҥȴ�Ϣ���뽸��ؿ������ݡ��Ȥ���ޤ��� �ʲ�����򼨤��ޤ���

例 8-4. ��󷿤ν��

INSERT INTO person VALUES ('Larry', 'sad');
INSERT INTO person VALUES ('Curly', 'ok');
SELECT * FROM person WHERE current_mood > 'sad';
 name  | current_mood 
-------+--------------
 Moe   | happy
 Curly | ok
(2 rows)

SELECT * FROM person WHERE current_mood > 'sad' ORDER BY current_mood;
 name  | current_mood 
-------+--------------
 Curly | ok
 Moe   | happy
(2 rows)

SELECT name FROM person
  WHERE current_mood = (SELECT MIN(current_mood) FROM person);
 name  
-------
 Larry
(1 row)

8.7.3. �������

��󷿤ϴ����˥ǡ�������ʬ����Ƥ��ꡢ�ߤ�����Ӥ��뤳�ȤϤǤ��ޤ���

例 8-5. ���㥹�Ȥη���

CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic');
CREATE TABLE holidays (                                           
    num_weeks int,
    happiness happiness
);
INSERT INTO holidays(num_weeks,happiness) VALUES (4, 'happy');
INSERT INTO holidays(num_weeks,happiness) VALUES (6, 'very happy');
INSERT INTO holidays(num_weeks,happiness) VALUES (8, 'ecstatic');
INSERT INTO holidays(num_weeks,happiness) VALUES (2, 'sad');
ERROR:  invalid input value for enum happiness: "sad"
SELECT person.name, holidays.num_weeks FROM person, holidays
  WHERE person.current_mood = holidays.happiness;
ERROR:  operator does not exist: mood = happiness

�⤷�����˾�Τ褦�ʤ��Ȥ�ɬ�פʤ�С��ȼ��α黻�Ҥ�������뤫���䤤��碌������Ū�ʥ��㥹�Ȥ��դ��뤳�ȤǹԤ����Ȥ��Ǥ��ޤ���

例 8-6. �ƥ����ȷ��˥��㥹�Ȥ��뤳�Ȥˤ��ۤʤ���󷿤����

SELECT person.name, holidays.num_weeks FROM person, holidays
  WHERE person.current_mood::text = holidays.happiness::text;
 name | num_weeks 
------+-----------
 Moe  |         4
(1 row)

8.7.4. �����ξܺ�

��󷿤��ͤϥǥ�������Ǥ�4�Х��Ȥ����ޤ��� ��󷿤��ͤΥƥ����ȥ�٥��Ĺ���ϡ�PostgreSQL���Ȥ߹��ޤ줿NAMEDATALEN����ˤ�����¤���ޤ��� ɸ��ι��ۤǤϡ�����Ϥ��褽63�Х��Ȥ��̣���ޤ���

��󷿤Υ�٥�Ǥ���ʸ����ʸ������̤��ޤ��� ���Τ���'happy'��'HAPPY'��Ʊ���ǤϤ���ޤ��� ��٥���ζ���ʸ�����̣������ޤ���