acrolink

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

kip

ex_cldr Core Team

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

hauleth

As ISBN numbers can start with 0 the only proper way to store it is to use string or array of digits.

LostKobrakai

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

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.

Where Next?

Popular in Questions Top

dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement