acrolink
Storing an ISBN-13 as string or integer (PostgreSQL)
I want to store books details in a PostgreSQL table. There will be a field with unique constraint holding book’s ISBN-13 number (example formatted as string as: 978-0-545-01022-1). This field can be the primary key field and would be indexed.
My question, should I store it as:
978-0-545-01022-1 i.e. string
or
9780545010221 i.e. integer ?
Performance wise and/or due to other considerations, what do you think? Thank you.
Most Liked
kip
I think the answer partly depends on whether you care about the sub parts of of the ISBN-13, for example searching on books in a certain country or publisher. it also depends on whether you need to support ISBN-10 which allows for the character X as the check digit.
If you store as a string then I would suggest you remove any non-digits to formatting separate from validation.
There is a GTIN validation lib you might find useful too since an ISBN-13 is a subset of a GTIN.
hauleth
As ISBN numbers can start with 0 the only proper way to store it is to use string or array of digits.
LostKobrakai
An isbn is an identifier not a number. You’ll never want to perform arithmetic with isbns. Therefore you probably should use a string column and a canonical format for the isbn. I see many identifiers more like names, which just happen to be only comprised of digits.
Last Post!
ArthurClemens
For the archives: GitHub - Frost/isn: Postgrex.Extension and Ecto.Type for PostgreSQL isn module · GitHub handles the isn Postgres extension for Postgrex. It accepts both strings (with or without dashes) and integers.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









