1

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.

1 Answer 1

3

You could use a check constraint:

ALTER TABLE yourTable
ADD CONSTRAINT rate_check CHECK (city_rate >= 1.0 AND city_rate <= 10.00);
Sign up to request clarification or add additional context in comments.

1 Comment

A tiny simplification idea: ADD CONSTRAINT rate_check CHECK (city_rate BETWEEN 1 AND 10)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.