In PostgreSQL I have a column city_rate
value NUMERIC DEFAULT 1.00
.
Is there a way from postgres to enforce that value to be between two values: 1.00 & 10.00.
Like if user INSERT or UPDATE city_rate
with a value greater than 10.00 it will save it as 10.00, or if the value is lower than 1.00 it will be saved as 1.00.
CodePudding user response:
You could use a check constraint:
ALTER TABLE yourTable
ADD CONSTRAINT rate_check CHECK (city_rate >= 1.0 AND city_rate <= 10.00);