D
D
Dilik Pulatov2022-02-06 17:15:41
PostgreSQL
Dilik Pulatov, 2022-02-06 17:15:41

PostgrSQL - What is the best data type to use for statuses, object types, etc?

I often use custom types for statuses, etc.

CREATE TYPE order_status AS ENUM ('new', 'open', 'closed');

Not long ago, familiar programmers suggested using TINYINT for such fields.
I don't change lists like this very often. Therefore, custom types are enough for me.
But after it was suggested to use TINYINT better, I began to search Google for the pros and cons of these types.
So far haven't found anything. Somewhere they say ENUM types are evil. but there is an ENUM type in MySQL. And in PostgrSQL, these are just custom types.
It is important that then there is no performance problem. For me, the speed of CRUD requests is important.
What is the difference between these types? What are the pros and cons?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2022-02-06
@ky0

Taste.

V
Vitsliputsli, 2022-02-06
@Vitsliputsli

What is the difference between these types? What are the pros and cons?

In fact, you have an enum, and then the question of how to store it, as an enum or as a number, will sound: where to implement the enum in the code or in the database. The implementation in the code will allow validating this enum at the application level without additional queries to the database, otherwise it all falls on the DBMS. Otherwise, there is no difference.
Because The database is always a bottleneck, then I would implement it in the code, but there are adherents who believe that everything needs to be pushed into the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question