acrolink

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.

Showing Posts 1 to 10

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.

acrolink

acrolink OP

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

acrolink OP

But is there a performance impact between storing it as integer or string? When searching the DB? or making joins?

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.

NobbZ

NobbZ

More important than the type, is probably the index. If you do not have that column indexed, its slow…

acrolink

acrolink OP

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-0

All 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

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

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 isn module, supplied with Postgres, which probably has what you need.

  1. Good news: Amazon supports isn on RDS.

  2. You might need deal with low-level Ecto / Postgrex primitives to use isn with Ecto, but if that is a core concern of your application it could be worth the effort.

  3. Further,

evadne=# select '978-0-545-01022-1'::isbn13;
      isbn13       
-------------------
 978-0-545-01022-1
(1 row)

evadne=# select '9780545010221'::isbn13;
      isbn13       
-------------------
 978-0-545-01022-1
(1 row)
  1. In certain cases you can cheese it by specifying a field as string in Ecto and actually using a more detailed type in Postgres.
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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews