RE: Data Type to store Leading Zero(0)

From: "Michel SALAIS" <msalais(at)msym(dot)fr>
To: <soumik(dot)bhattacharjee(at)kpn(dot)com>, <pgsql-admin(at)postgresql(dot)org>
Subject: RE: Data Type to store Leading Zero(0)
Date: 2021-01-22 07:57:25
Message-ID: 02df01d6f094$3a7301d0$af590570$@msym.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi,

First of all, if you consider 0001 and 00001 as different values then you
have two solution

* the solution proposed by Kanninen
* using string values and the column should be defined as varchar (or
text)

If 0001 and 00001 are considered the same or let’s say that it is impossible
to have these two values in your primary key then the question is simply a
representation one and the choice should be

* numeric, int, bigint, … whatever convenient of these types
* Use of to_char() with appropriate format when displaying theses
values. This lets you specify that leading zeros must be displayed like this

select to_char(12, '0999');

to_char

---------

0012

Regards

Michel SALAIS

De : soumik(dot)bhattacharjee(at)kpn(dot)com <soumik(dot)bhattacharjee(at)kpn(dot)com>
Envoyé : mercredi 20 janvier 2021 12:14
À : pgsql-admin(at)postgresql(dot)org
Objet : Data Type to store Leading Zero(0)

Hello Experts,

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.

Please suggest.

Thanks

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message pavan srivathsav 2021-01-22 08:04:27 Regarding 500 Internal Server Error
Previous Message Tom Lane 2021-01-20 20:27:18 Re: TIL: In pg_dump, beware the combo of "-Fd" and "-Z"