From: Michel SALAIS <msalais@msym.fr>
To: soumik.bhattacharjee@kpn.com
To: pgsql-admin@postgresql.org
Subject: RE: Data Type to store Leading Zero(0)
Date: Fri, 22 Jan 2021 08:57:25 +0100
Message-ID: <02df01d6f094$3a7301d0$af590570$@msym.fr> (raw)
In-Reply-To: <c77968e8e35a4e9d8f68c2683ae1b807@kpn.com>
References: <c77968e8e35a4e9d8f68c2683ae1b807@kpn.com>
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.bhattacharjee@kpn.com <soumik.bhattacharjee@kpn.com>
Envoyé : mercredi 20 janvier 2021 12:14
À : pgsql-admin@postgresql.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: msalais@msym.fr, soumik.bhattacharjee@kpn.com
Subject: RE: Data Type to store Leading Zero(0)
In-Reply-To: <02df01d6f094$3a7301d0$af590570$@msym.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox