Re: Data Type to store Leading Zero(0)

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: soumik(dot)bhattacharjee(at)kpn(dot)com
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Data Type to store Leading Zero(0)
Date: 2021-01-20 14:49:34
Message-ID: CAKFQuwYWjKAiZjMg38E2DBj8iZFdPncTgJHVJiM6PAGbVxV4Lg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Wed, Jan 20, 2021 at 4:13 AM <soumik(dot)bhattacharjee(at)kpn(dot)com> wrote:

> As per business needs we need to store Zero(0) in primary key column of
> table with this kind of value à 07******** with applications written in
> Java microservices.
>
>
>
> We are not able to use *numeric data type *as it trims the Zero value in
> leading, but it’s also a performance impact if we define *varchar* in the
> data type.
>

A true number stores leading zeros since all bits in the representation are
always present regardless of whether they are zero or one. Thus it is a
cosmetic presentation choice to suppress displaying those leading zeros,
not a storage one.

If these aren't true numbers, i.e., "0001" and "000001" are actually
different, then what you have is a string that only uses numbers. Model
that using text and let the performance fall where it will.

David J.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Ankush Chawla 2021-01-20 15:56:20 standby compatibility matrix
Previous Message Thomas Kellerer 2021-01-20 12:39:50 Re: Data Type to store Leading Zero(0)