SQL
Enum Usage
After an enum has been created, it can be used anywhere a standard built-in type is used. For example, we can create a table with a column that references the enum.  
Creates a table `person`, with attributes `name` (string type) and `current_mood` (mood type):  
```sql
CREATE TABLE person (
name TEXT,
current_mood mood
);
```  
Inserts tuples in the `person` table:  
```sql
INSERT INTO person
VALUES ('Pedro', 'happy'), ('Mark', NULL), ('Pagliacci', 'sad'), ('Mr. Mackey', 'ok');
```  
The following query will fail since the mood type does not have `quackity-quack` value.  
```sql
INSERT INTO person
VALUES ('Hannes', 'quackity-quack');
```  
The string `sad` is cast to the type `mood`, returning a numerical reference value.
This makes the comparison a numerical comparison instead of a string comparison.  
```sql
SELECT *
FROM person
WHERE current_mood = 'sad';
```  
|   name    | current_mood |
|-----------|--------------|
| Pagliacci | sad          |  
If you are importing data from a file, you can create an enum for a `VARCHAR` column before importing.
Given this, the following subquery selects automatically selects only distinct values:  
```sql
CREATE TYPE mood AS ENUM (SELECT mood FROM 'path/to/file.csv');
```  
Then you can create a table with the enum type and import using any data import statement:  
```sql
CREATE TABLE person (name TEXT, current_mood mood);
COPY person FROM 'path/to/file.csv';
```