4 ms·
You can put check constraints on a TEXT field to prevent bad data.
by joevandyk 13y ago
You can put check constraints on a TEXT field to prevent bad data.
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- Demiurge 13y agoIsn't that what varchar basically is?
- jeltz 13y agoYes, but with some minor caveats[1]. I prefer always using check constraints since then you get all length constraints in the same place in the table definition. 1. The SQL standard requires truncation of trailing excess spaces on inserts which overflow the limit. Additionally the limit must be less or equal to 10485760 which is less than the maximum length of a string which is 1GB.
- radiowave 13y agoOne difference is that changing the length of a varchar column in an existing table can be a major pain if you have other database objects that must be the same type. For example, any views which also carry this column will need to be dropped and recreated (or otherwise modified), or else Postgres won't allow you to make the change. Working with the text datatype and using check constraints on length makes this much easier.