From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | vod vos <vodvos(at)zoho(dot)com>, 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 16:39:01 |
Message-ID: | 15358.1489336741@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Sun, Mar 12, 2017 at 12:00 AM, vod vos <vodvos(at)zoho(dot)com> wrote:
>> 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.
Yeah. I wonder if the OP wouldn't be better off thinking of his data as
strings rather than numbers. The format requirement could be expressed
as a CHECK constraint, along the lines of length(goose) = 5 AND
goose ~ '^\d+\.\d+$' (or possibly \d* if zero digits on one side of
the decimal point is OK). You could imagine storing as numeric and
having CHECK constraints that cast to string and make those tests,
but I fear trailing zeroes would break it.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | sttefaniribeiro | 2017-03-12 18:30:03 | general erros backup |
Previous Message | Adrian Klaver | 2017-03-12 15:11:44 | Re: How to define the limit length for numeric type? |