Add constains to column

I want to add a constrain to the column but it throws an error. Any suggestions?
(length(name) > 4 && length(name) < 18
(length(name) > 4 && length(name) < 18
4 Replies
Shufflepuff
Shufflepuff2y ago
What's the error it's throwing? The code you posted is missing a closing bracket Additionally I'd say it has to be AND instead of &&"
length(name) > 4 AND length(name) < 18
length(name) > 4 AND length(name) < 18
Afaik you could also use
length(name) BETWEEN 5 AND 17
length(name) BETWEEN 5 AND 17
ummahusla
ummahuslaOP2y ago
BETWEEN X AND Y is exactly what I was looking for! Thank you.
Shufflepuff
Shufflepuff2y ago
np, while I was testing it, I wanted to delete the constraint again, but when I wanted to just empty the field and save the column again I got an error. Not sure if it's the same for you, but if so, you can drop the constraint with this:
ALTER TABLE your_table_name
DROP CONSTRAINT yourTableName_yourColumnName_check;
ALTER TABLE your_table_name
DROP CONSTRAINT yourTableName_yourColumnName_check;
Feel free to add the "✅ Solved" tag to your post 🙂
ummahusla
ummahuslaOP2y ago
Done, thank you

Did you find this page helpful?