Hacker News new | ask | show | jobs
by marcosdumay 1102 days ago
> Can you elaborate on what it means to use PostgreSQL enums "on your code API"?

If you export a procedure for creating a socket into pgPlSQL, you shouldn't use magical numbers for setting the socket flags. You should use enums.

As for sqlalchmey, well that design is not good. It should support more mappings than just to string. But well, personally, I would ignore the feature and go without enum types (notice that it's a recent addition). You can always declare your own enum and convert the column if you want.

2 comments

> But well, personally, I would ignore the feature and go without enum types (notice that it's a recent addition).

Postgres has had enums since 2008

So, recent addition.
I would argue "certainly not", since it's had them for more than half its lifetime.
I still don't totally understand that first point. Are you talking about using enums for controlling the connection itself? Can you give an example?

Just to clarify, sqlalchemy supports any arbitrary mapping you want — it's entirely flexible in every direction.

EDIT ah, do you mean something like this?

    CREATE FUNCTION do_thing(flags custom_enum)
Yep, you use it as CREATE FUNCTION do_something(some_option custom_enum). The main use-case is not putting them on tables.

Relational algebra has the concept of enums builtin (as long as they all have the same structure). You create them in databases by using foreign keys.