Search code examples
mysqlgoogle-plus

What's the best column type for Google+ User ID?


Google+ has very long User IDs

104560124403688998123

(21 characters), which is not possible to input into BIGINT field (not unsigned)

What column type would you use for such IDs ?

I do not think that varchar is good idea


Solution

  • if the length of the google id is predictable, use a static char(length), add an index on it and create an (internal) integer primary key. Inside of your application you map the data to the integer primary key. So if someone searches by google id, you lookup the integer primary key for this google id and do the rest of your queries with the integer primary key.

    So the schema looks like:

    Mapping Table:

    id (integer) | google_id (char(length)) 
    

    So if you create another table like comments etc, use the primary key id, if you want to lookup all comments for a certain googleid, get the internal id first and then join the comments. This way you have only one query criteria on a static, indexed char field with a predictable length, all other joins and queries will use the integer key.