Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can put check constraints on a TEXT field to prevent bad data.


Isn't that what varchar basically is?


One 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.


Yes, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: