Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please don't top-post on these lists.

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux