I have 18 character long IDs I get from an API, and I currently store them as varchar(20). They are used as primary and foreign keys. Is it better in my case, to use bigint instead of a string type, performance-wise?

Since JavaScript cannot deal with bigints, they are converted by default to string, but I could set columns to be bigint, if that will help.

  • 1
    In common joining/referencing by bigint is more safe than that by varchar. So storing your IDs as a common unique attribute and using bigint synthetic primary (and foreign) key may be more appropriate.
    – Akina
    Nov 5 '18 at 9:35
  • Why is it more safe? I would say it is slightly more efficient.. with both types you can have missing values if you don’t enforce FKs.
    – eckes
    Nov 5 '18 at 11:04

Definitely store as a bigint: this uses 8 bytes, while an 18 character string uses 19 bytes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.