acrolink
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.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Other Trending Topics
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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
Xas 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.
acrolink
Seems true for old ISBN i.e. ISBN-10 but for new version ISBN-13, maybe cannit start with zero. Actually, I will convert all to ISBN-13 before storing in DB.
acrolink
But is there a performance impact between storing it as integer or string? When searching the DB? or making joins?
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.
NobbZ
More important than the type, is probably the index. If you do not have that column indexed, its slow…
acrolink
I will store all as ISBN13, but yet there is some not programming related issue here:
An ISBN13 looks like this:
978-3-16-148410-0All fine, there are 5 groups within the number and they don’t have fixed size. The second group can be 1 or 2 digits. So, it is logical that the dashes should be stored as part of the identifying. Yet, all books I have tested have bar-codes storing the ISBN13 as digits only (integer) with no dashes.
The whole point is to read with a bar-code scanner the ISBN13 and look up book’s info in the database. As such, storing it as an integer, the way the barcodes are printed on the books is the way to go.
And of course, all can be changed later, depending on the needs.
NobbZ
No, bardcodes do not store them as integer, barcodes do “store” them as individual digits.
Barcodes have a very limited alphabet available, it does only know about the digits 0 through 9. And maybe one or two extra “characters”, but thats basically it.
evadne
You could do it the hard way and make a Composite Type or a Domain…
Or do it the easy way and use the
isnmodule, supplied with Postgres, which probably has what you need.Good news: Amazon supports
isnon RDS.You might need deal with low-level Ecto / Postgrex primitives to use
isnwith Ecto, but if that is a core concern of your application it could be worth the effort.Further,
ArthurClemens
For the archives: GitHub - Frost/isn: Postgrex.Extension and Ecto.Type for PostgreSQL isn module · GitHub handles the
isnPostgres extension for Postgrex. It accepts both strings (with or without dashes) and integers.