Re: How to define the limit length for numeric type?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: vod vos <vodvos(at)zoho(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to define the limit length for numeric type?
Date: 2017-03-12 07:20:52
Message-ID: CAKFQuwZO17LkR2t3WHhVPPqr8rznpjiubGCZZRS0SErnXesiRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Please don't top-post on these lists.

On Sun, Mar 12, 2017 at 12:00 AM, vod vos <vodvos(at)zoho(dot)com> wrote:

> Maybe CHECK (goose >= 100 AND goose <= -100) works better, But if :
>
> INSERT INTO test VALUES (1, 59.2);
> INSERT INTO test VALUES (1, 59.24);
> INSERT INTO test VALUES (1, 59.26);
> INSERT INTO test VALUES (1, 59.2678);
>
> The INSERT action still can be done. What I want is just how to limit the
> length of the insert value, you can just type format like 59.22, only four
> digits length.
>

length(trunc(goose, 0)::text) + scale(goose)

I suspect you might encounter some issues, namely around
123.456789::numeric(6,1) casting behavior and maybe
00059.12000::numeric(6,1) treatment of unimportant zeros. I haven't tested
any of that. The above will get you a single length value for a given
input.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Charles Clavadetscher 2017-03-12 07:21:16 Re: How to define the limit length for numeric type?
Previous Message vod vos 2017-03-12 07:00:58 Re: How to define the limit length for numeric type?