by rpedela · 13y ago · 0 comments
CREATE TABLE t (col TEXT CHECK length(col) < 50);
What is nice is that you just need to add/drop a constraint if you want to change the max value check rather than changing the data type which can result in a table rewrite depending on the scenario. You can also add a min length check as well using this method or regex check, etc.
I think the author should have made this point rather than just glossing over it with "constraints, triggers are more flexible".
What the benchmarks show, if anything, is that while the `check` involves negligible overhead per row, the overhead can eventually be enough to make a measurable difference.
Not to mention, the Postgres actually manual says as much as the above, in its description of text types.