Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify numeric column between 1 and 5

Tags:

sql

postgresql

I am trying to set up a numeric column in a postgresql table. This column may only contain a number between 1 and 5.

How should i specify this in my postgresql?

like image 356
Markie Doe Avatar asked Nov 15 '25 05:11

Markie Doe


1 Answers

You want a constraint

CREATE TABLE mytable (
    constraint_col integer  CHECK (constraint_col > 0 and constraint_col < 6)
);
like image 81
e4c5 Avatar answered Nov 17 '25 22:11

e4c5



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!