Primary keys in Room should be Int or Long?

Both is fine. On mobile (and most of the time in general) Int should be sufficient (it will also save you 4 bytes over Long).

Why? Using an Int you could store over 2 billion records (2_000_000_000). So you could store a record of around 1/4 of all the humans living on earth. Just for comparison: Using a Long would enable you to store over 900 quadrillion records (900_000_000_000_000_000).


Both of these types will map to an INTEGER in the underlying SQLite database.

For example, with a class like this:

@Entity
data class Test(@PrimaryKey val i: Int, val l: Long)

You'd get a SQLite table defined with this query:

CREATE TABLE IF NOT EXISTS `Test` (`i` INTEGER NOT NULL, `l` INTEGER NOT NULL, PRIMARY KEY(`i`))

So you can use whichever one you'll need the magnitude of in your code. If you do decide to use an Int for some reason and you run out of values, you can even change it to a Long without having to migrate your database later on.

As for this INTEGER type, as per the SQLite documentation:

The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.