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]

 



"David G. Johnston" <david.g.johnston@xxxxxxxxx> writes:
> On Sun, Mar 12, 2017 at 12:00 AM, vod vos <vodvos@xxxxxxxx> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[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