As far as I see the Postgresql documentation on enum types only says:
Enumerated (enum) types are data types that comprise a static, ordered set of values.
So I tried the following:
create type foo as enum (1, 2, 3);
, but got
[42601] ERROR: syntax error at or near "1"Position: 26
My assumption is that enums only support text
as value, but I don’t really see this in the documentation. Can someone confirm my assumption? And if it is in the documentation please point me there.
2
Answers
They aren’t text – they are enumerated values.
Different enum types aren’t comparable either – they are different types.
Now, a lot of C-derived programming languages have enums as named identifiers for integers, but they are an actual type here.
You do enter literal enum values by quoting them, like almost every type apart from numbers and booleans. That’s obviously necessary if you want enumerated values to consist of something other than digits. But they aren’t
text
.Enum labels have to be string constants.
This is documented here:
Single quotes imply a string constant.