Skip to content
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

Open
phenomen2277 opened this issue Jan 21, 2016 · 8 comments
Open

The ids are not unsigned #8

phenomen2277 opened this issue Jan 21, 2016 · 8 comments

Comments

@phenomen2277
Copy link

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

@caboteria
Copy link
Owner

Not sure. What are the consequences of negative ids?

@phenomen2277
Copy link
Author

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

@caboteria
Copy link
Owner

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.

@phenomen2277
Copy link
Author

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.

@hjdivad
Copy link
Collaborator

hjdivad commented Jan 25, 2016

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?

@phenomen2277
Copy link
Author

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 :)

@hjdivad
Copy link
Collaborator

hjdivad commented Jan 25, 2016

@caboteria yes sorry i've edited my comment. Having signed ids seems very strange to me. Having unsigned ids seems the more natural thing.

@kwent
Copy link

kwent commented Jun 1, 2016

FYI. PosgreSQL has bigserial type for signed ids.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants