Native enums can be used in queries like strings, but with type checking: select * from cust where type = ’company’ -- ok select * from cust where type = ’c0mpany’ -- error As mentioned, they take less space. Important if you use these columns in index and have millions of rows.
Representing Enums in PostgreSQL
71–76 of 76 posts
Re: Representing Enums in PostgreSQL
#72Earlier quoted context omitted.
Can you elaborate on what it means to use PostgreSQL enums "on your code API"? > It's such an outrageously naive idea that I'm sure most people here were attracted to the title thinking it's about algebraic types or some other similar misunderstanding. Just to share how we at Close got into this discussion (which I personally don't find as "outrageous" as you), SQLAlchemy – which we use in our Python code – uses `nat…
> 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 i…
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)Re: Representing Enums in PostgreSQL
#73Re: Representing Enums in PostgreSQL
#74Earlier quoted context omitted.
> 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 i…
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)
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.
Re: Representing Enums in PostgreSQL
#75Native enums can be used in queries like strings, but with type checking: select * from cust where type = ’company’ -- ok select * from cust where type = ’c0mpany’ -- error As mentioned, they take less space. Important if you use these columns in index and have millions of rows.
Re: Representing Enums in PostgreSQL
#76The article misses the most common way to represent enums: foreign keys…