-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The ids are not unsigned #8
Comments
Not sure. What are the consequences of negative ids? |
it seems that the rails ppl generate ids signed by default. Do not know what is that!? The ids should be unsigned :) https://dev.mysql.com/doc/refman/5.5/en/integer-types.html |
I'm not opposed to having them unsigned but I still don't see any evidence of benefit. The link you provided simply describes the integer types and their sizes, it doesn't have any info on whether PK's should be unsigned. On a practical basis, you're unlikely to have 2^63-1 rows in your database so it's unlikely to matter. |
That is why i wrote that it was the rails ppl. It is their problem. But by having the ids unsigned, you are able to have many many more rows in a table. anyways. Thank you. But it is till nice to provide this feature in your gems if possible. Since there are ppl using it. |
FWIW having signed ids seems very strange to me. I expect a lot of code would act weirdly with negative IDs and I don't see any reason for restricting the ID-space. @caboteria it's true that 2^63-1 is a large number but it still seems to me to be better to not restrict the ID-space. A larger space opens up other possibilities, like using the upper 32 bits for namespacing and the lower 32 bits for conceptual IDs. Obviously you can still do something like that with signed ints but it seems more error prone to have a signed int that you sometimes interpret as unsigned. If you're not against it maybe this is a "patches welcome" situation? |
pg has no unsigned bigint, but the 3 dbms mysql, pg & sqlite3 do have support for singed 64bit integers, which in my opinion should be the default datatype in rails. But that is up to the rails core team :) |
@caboteria yes sorry i've edited my comment. Having signed ids seems very strange to me. Having unsigned ids seems the more natural thing. |
FYI. PosgreSQL has Cf. https://www.postgresql.org/docs/9.1/static/datatype-numeric.html On rails you can now do create_table :table_name, id: :bigserial do |t|
# definitions
end But apparently this is not a real type and more a trick according to http://stackoverflow.com/questions/31965506/postgresql-column-type-conversion-form-bigint-to-bigserial |
An object's id should be greater_than 0. Do not you agree!? :) It may be an activerecord convention to do so. I do not know
The text was updated successfully, but these errors were encountered: