E
E
Egor Telnov2019-10-28 18:52:19
PostgreSQL
Egor Telnov, 2019-10-28 18:52:19

How to create an enum type?

Hello! I want to create a custom data type so that there are values ​​from 10 to 200. How can this be implemented?
Esteemed to dock, nothing is clear
I write so: create type name as range (). What should be passed as input?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-10-28
@telnov_magic

Well, it depends on what exactly you want to do.
PostgreSQL allows you to make your own data type implementation. Which will behave as you want - but you have to develop all this logic yourself in C. Therefore, create type has quite voluminous documentation.
range types are ranges. For example, the date of booking a hotel room. Booking table, one field with tsrange date range and exclude constraint - that's it, the database will check that the booking dates do not overlap.
enums - this is usually meant by enum. But it doesn't work for your task. enum is a fixed set of strings.
something similar to regular data types, but with limitations - you wanted to find not create type, but create domain:
That's it, now in tables you can use the data type smallint_between_10and200, in which, nevertheless, it will be impossible to write something not from the range of 10..200.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question