没有以所述方式限制数值的内置功能。您可以创建并使用函数来实现此行为:
create or replace function limited_numeric(val numeric, prec int, scale int)
returns numeric language sql immutable as $$
select least(mx, val)
from (
select format('%s.%s', repeat('9', prec- scale), repeat('9', scale))::numeric as mx
) s
$$;
用法示例:
insert into products
values (1, 'article 1', 'name 1', limited_numeric(12345678, 10, 3))
returning *;
id | article | name | quantity
----+-----------+--------+-------------
1 | article 1 | name 1 | 9999999.999
(1 row)