using varchar over varchar(n) with Postgresql

℡╲_俬逩灬. 提交于 2020-01-16 10:36:09

问题


I'm designing a database, since I'm not yet confortable with the data types I was wondering the following :

If I don't care about the length of a vector of characters, is it appropriate to use varchar ? (even if the strings are expected to be quite short ?)

Until now I've been using text (varchar) when I needed to store really long strings but reading the documentation and asking questions around I heard postgresql does not store the extra-bytes if the maximum-length is supplied and the stored string's length is lesser than it. I guess the maximum-length is used in case the distant device can't afford large memory space. Could one agree or explain that ?


回答1:


From the docs:

There is no performance difference among these three types, 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.



来源:https://stackoverflow.com/questions/16525701/using-varchar-over-varcharn-with-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!