Re: Data Type to store Leading Zero(0)

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: soumik(dot)bhattacharjee(at)kpn(dot)com, nidhig631(at)gmail(dot)com
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Data Type to store Leading Zero(0)
Date: 2021-04-15 13:54:29
Message-ID: 770d9e620ade5e492c9aa4545c8e182cd6526884.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Nidhi Gupta <nidhig631(at)gmail(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.

Use "integer" and define a view that pads the column with zeros on the
left side:

CREATE VIEW myview AS
SELECT lpad(if::text, 10, '0') AS id,
othercolumn,
...
FROM mytable;

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Paul Smith 2021-04-15 15:04:53 Re: Data Type to store Leading Zero(0)
Previous Message David G. Johnston 2021-04-15 13:53:19 Re: Data Type to store Leading Zero(0)