3 ms·
> Have a single 'name' field which is over 200 characters long? Or, as postgresql calls it, "varchar": > The storage requirement for a short string (up to 126
by masklinn 8y ago
> Have a single 'name' field which is over 200 characters long?
Or, as postgresql calls it, "varchar":
> The storage requirement for a short string (up to 126 bytes) is 1 byte plus the actual string, which includes the space padding in the case of character. Longer strings have 4 bytes of overhead instead of 1. Long strings are compressed by the system automatically, so the physical requirement on disk might be less. Very long values are also stored in background tables so that they do not interfere with rapid access to shorter column values. In any case, the longest possible character string that can be stored is about 1 GB.
- JessicaTG 8y agoOr just use "text" :-) There's no storage advantage using varchar in PostgreSQL. Just the length constraint checking.
- masklinn 8y ago> There's no storage advantage using varchar in PostgreSQL. Just the length constraint checking. Contrariwise there's no advantage to using text either.
- throwaway2048 8y agoLonger than 200 characters?
- masklinn 8y agoMakes no difference to postgres. The one and only difference is that you can limit the length of a varchar when you define the column but that aside the storage mechanism is the one I quoted above for both, and for char as well: > There is no performance difference among these three types (nb: varchar, char and text), apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead. And for applications which introspect the schema and display different field types depending on the column type, well you may not want a textarea for a name field.
- pandler 8y agoWhere’s a reasonable cut off point? Surely you don’t want someone uploading a copy of War and Peace as their name.