types = { # add your custom types here 'attendance': ('Notconfirmed','Coming', 'Notcoming', 'Maycome',), } CREATE TYPE attendance AS ENUM types;
The above query creates enum type attendance with enumlabels mentioned in types. How to create a type with default label? In this case the I want to create attendance type with default value Notconfirmed.
The default value for an enum is zero. If an enum does not define an item with a value of zero, its default value will be zero.
One consideration for the use case where a default enum is desired is to use a nullable variable. When a null is received, it can be translated in the correct part of the code into the default, and this default doesn't have to be known in the rest of the code (that just passes along a null).
The default value of an enumeration type E is the value produced by expression (E)0 , even if zero doesn't have the corresponding enum member. You use an enumeration type to represent a choice from a set of mutually exclusive values or a combination of choices.
By default, the value of the first enumerator is zero if it is implicitly defined. The value of each subsequent implicitly-defined enumerator is the value of the previous enumerator + 1. (Optional) The name of a variable of the enumeration type.
I was trying the same as you, and I got answer in stackoverflow only, It is possible to create ENUM with default value. Here is what I got for you.
CREATE TYPE status AS ENUM ('Notconfirmed','Coming', 'Notcoming', 'Maycome'); CREATE TABLE t ( id serial, s status default 'Notconfirmed' -- <==== default value ); INSERT INTO t(id) VALUES (default) RETURNING *;
This worked for me like a charm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With