Comments (4)
The primary reason why I wanted to use string enums in the first place was the opacity of having integers in the SQL output, so yes while you can avoid one particular footgun with the enum
helper by being more explicit, it doesn't solve the core problem.
I was only noting the size of the enum bytes to illustrate that you're not paying a significant cost by using them, I doubt the difference between four or two bytes would really matter to most people. It's noteworthy that enums are not integers in PostgreSQL because they use a floating point to support adding a new value in between existing ones.
from activerecord-pg_enum.
The primary reason why I wanted to use string enums in the first place was the opacity of having integers in the SQL output
ahh, gotcha
It's noteworthy that enums are not integers in PostgreSQL because they use a floating point to support adding a new value in between existing ones.
I don't think that's true
https://www.postgresql.org/docs/13/datatype-enum.html#id-1.5.7.15.8
"Existing values cannot be removed from an enum type, nor can the sort ordering of such values be changed, short of dropping and re-creating the enum type. An enum value occupies four bytes on disk. "
from activerecord-pg_enum.
I said adding a new value, not changing an existing one.
https://www.postgresql.org/docs/13/catalog-pg-enum.html
When an enum type is created, its members are assigned sort-order positions 1..n. But members added later might be given negative or fractional values of
enumsortorder
. The only requirement on these values is that they be correctly ordered and unique within each enum type.
This is how they support adding new values before or after existing values
from activerecord-pg_enum.
Ah gotcha - I guess I need to grok this more. Thanks for the discussion!
from activerecord-pg_enum.
Related Issues (14)
- Application does not boot when also using active_record_extended HOT 4
- Schema dumper assumes that enum values will not contain spaces HOT 4
- Support Rails enum options HOT 3
- enum helper not working with change_table HOT 3
- `create_enum` not getting dumped to schema.rb HOT 5
- Support for renaming, removing enum values HOT 1
- Consider removing enum types as part of `db:drop` / `db:reset` HOT 6
- Support Rails 6.1 HOT 1
- Thoughts on new feature: force cascade for create_enum HOT 2
- Segmentation fault for Ruby 3.0 HOT 5
- Cannot add new enum value HOT 2
- Rails 7 support HOT 10
- Rails 7 support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activerecord-pg_enum.