Git Product home page Git Product logo

Comments (4)

alassek avatar alassek commented on July 25, 2024

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.

jjb avatar jjb commented on July 25, 2024

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.

alassek avatar alassek commented on July 25, 2024

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.

jjb avatar jjb commented on July 25, 2024

Ah gotcha - I guess I need to grok this more. Thanks for the discussion!

from activerecord-pg_enum.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.