Pergunta

I'm using Google as a login system for my latest project. So, my users table has a column named googleid, which stores Google's unique user id, which is a number, with a few dozen digits. For example, it might be 105561241212957286025. Since I'm not going to do any mathematical operations on this data, should I store it as a number, or as a string, in my database? Also note that if I used a numerical value I would actually have to specify a custom precision because the built-in numerical types in PostgreSQL aren't big enough for this value.

Foi útil?

Solução

Store it as a string.

You've already stated some of the reasons why:

  1. You're not going to do any mathematical operations on it
  2. You need a very large precision number to store that many digits

Let me give you a few more reasons:

  1. ID's don't conceptually have a sequence or sort order, nor should they. ID's therefore have no numeric semantics whatsoever; the only advantage numbers might have is storage size.
  2. Use a string, and if Google decides to change to GUIDs or base64 numbers for their ID's, your project will still work.

I have been using Guid's for Primary Keys in SQL databases for awhile now, and I consider them ideal for ID's because

  1. They are globally-unique, so only joins that make sense will actually produce any output.

  2. They're 128 bit numbers internally, so they can be stored more efficiently than string keys. The hexadecimal representation just exists for display purposes.

Outras dicas

I think you should use string as a datatype of the column 'googleid' as you will not perform any mathematical operation on it in the future as well as you may face the problem of precision points in the PostgreSQL.

Licenciado em: CC-BY-SA com atribuição
scroll top