What is the size of the enum PostgreSQL type?

enums, postgresql, sql

Solution

The size of an enum is 4 byte on disk. Period. This is because enums are implemented as integers or shorts. The label to each integer value is saved in the system catalog `pg_enum`. You can have a look at it by simply querying it:

test=# select * from pg_enum;
 enumtypid | enumsortorder | enumlabel 
-----------+---------------+-----------
(0 rows)

test=# create type test_enum_t as enum('a','b','c');
CREATE TYPE
test=# select * from pg_enum;
 enumtypid | enumsortorder | enumlabel 
-----------+---------------+-----------
     68850 |             1 | a
     68850 |             2 | b
     68850 |             3 | c
(3 rows)

test=# 

Problem

I would like to know what is the size of an enum variable of PostgreSQL. For instance, if I create an enumeration type A with 100 different items, what would be the size in bytes of it? In addition, when I create a table that contains an attribute of type A, what is the size of this attribute? I checked the PostgreSQL documentation, but I didn't understand the last part that talk about the enum type sizes.

Original source