Re: [GENERAL] How to define the limit length for numeric type?
| От | Tom Lane |
|---|---|
| Тема | Re: [GENERAL] How to define the limit length for numeric type? |
| Дата | |
| Msg-id | 15358.1489336741@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: [GENERAL] How to define the limit length for numeric type? ("David G. Johnston" <david.g.johnston@gmail.com>) |
| Список | pgsql-general |
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sun, Mar 12, 2017 at 12:00 AM, vod vos <vodvos@zoho.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
В списке pgsql-general по дате отправления: