Re: [GENERAL] How to define the limit length for numeric type? - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] How to define the limit length for numeric type?
Date
Msg-id CAKFQuwZO17LkR2t3WHhVPPqr8rznpjiubGCZZRS0SErnXesiRA@mail.gmail.com
Whole thread Raw
In response to Re: [GENERAL] How to define the limit length for numeric type?  (vod vos <vodvos@zoho.com>)
Responses Re: [GENERAL] How to define the limit length for numeric type?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Please don't top-post on these lists.

On Sun, Mar 12, 2017 at 12:00 AM, vod vos <vodvos@zoho.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.

pgsql-general by date:

Previous
From: vod vos
Date:
Subject: Re: [GENERAL] How to define the limit length for numeric type?
Next
From: "Charles Clavadetscher"
Date:
Subject: Re: [GENERAL] How to define the limit length for numeric type?