This documentation is for an unsupported version of PostgreSQL.
당신은에 대해 같은 페이지를 보려고 할 수 있습니다PostgreSQL : 문서 : 17 : 8.7. 열거 된 토토 사이트버전 또는 위에 나열된 다른 지원 버전 중 하나입니다.

8.7. 열거 된 토토

Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to theenumtypes supported in a number of programming 언어. An example of an enum type might be the days of the week, or a set of status values for a piece of data.

8.7.1. Declaration of Enumerated Types

Enum types are created using theCREATE TYPE명령, 예 :

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

Once created, the enum type can be used in table and 다른 유형과 마찬가지로 함수 정의 :

예 8-3. 기본 열거

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
    이름 텍스트,
    current_mood mood
);
INSERT INTO person VALUES ('Moe', 'happy');
SELECT * FROM person WHERE current_mood = 'happy';
 이름 | current_mood 
------+--------------
 Moe  | 행복하다
(1 row)

8.7.2. 주문

The ordering of the values in an enum type is the order in which the values were listed when the type was created. 모두 standard comparison operators and related aggregate functions are supported for enums. 예를 들어:

예 8-4. 열거

INSERT INTO person VALUES ('Larry', 'sad');
개인 값에 삽입 ( 'Curly', 'Ok');
Current_mood 'SAD'가있는 사람에서 *를 선택하십시오.
 이름 | current_mood 
-------+-------------
 Moe   | 행복하다
 곱슬 | 좋아요
(2 줄)

current_mood 'SAD'순서가있는 사람 중에서 선택 *을 선택하십시오. current_mood;
 이름 | current_mood 
-------+-------------
 곱슬 | 좋아요
 Moe   | 행복하다
(2 줄)

이름을 선택하십시오 
사람에게서
여기서 current_mood = (개인에서 select min (current_mood));
 이름  
-------
 래리
(1 row)

8.7.3. 토토 안전

각 열거 된 데이터 토토은 분리되어 있으며 비교할 수 없습니다. 다른 열거 된 토토으로.

Example 8-5. Lack of Casting

CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic');
휴일 생성 (
    num_weeks 정수,
    행복 행복
);
휴일에 삽입 (NUM_WEEK, 행복) 값 (4, 'Happy');
휴일에 삽입 (Num_weeks, Happiness) 값 (6, '매우 행복');
휴일에 삽입 (Num_weeks, Happiness) 값 (8, 'Ecstatic');
휴일에 삽입 (Num_weeks, Happiness) 값 (2, 'SAD');
오류 : 열거 행복을위한 잘못된 입력 값 : "SAD"
Person.name, Holidays.num_weeks, Person, Holidays를 선택하십시오
  person.current_mood = holidays.happiness.
오류 : 운영자가 존재하지 않습니다 : mood = 행복

If you really need to do something like that, you can either write a custom operator or add explicit casts to your 질문:

예 8-6. 다른 열거를 비교합니다 텍스트에 캐스팅

Person.name, Holidays.num_weeks, Holidays를 선택하십시오
  person.current_mood :: text = holidays.happiness :: text;
 이름 | num_weeks 
------+----------
 모에 |         4
(1 행)

8.7.4. 구현 세부 사항

An enum value occupies four bytes on disk. An의 길이 열거 값의 텍스트 레이블은에 의해 제한됩니다.paminatalensetting compiled intoPostgreSQL; in standard builds this means at most 63 bytes.

Enum labels are case sensitive, so'행복한'is not the same as'행복한'. 라벨의 공백은 중요합니다 도.

The translations from internal enum values to textual labels 시스템 카탈로그에 보관pg_enum. 이 카탈로그를 직접 쿼리하는 것은 유용 할 수 있습니다.