字符串型別

Character Types

名字描述
character varying(n), varchar(n)變長,有長度限制
character(n), char(n)定長,不足補空白
text變長,無長度限制


這三種類型之間沒有性能差別,只不過是在使用 character 的時候增加了存儲尺寸(並使用空白填補型態), 以及少量額外CPU循環以長度限制欄位來檢查資料長度。雖然在某些其它的資料庫系統裡,character(n) 有一定的性能優勢,但在 PostgreSQL 裡沒有。在大多數情況下,應該使用 text 或 character varying

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. [1]

長的字符串將會自動被系統壓縮,因此在磁盤上的物理需求可能會更少些。長的數值也會存儲在後台表裡面,這樣它們就不會干擾對短字段值的快速訪問。不管怎樣,允許存儲的最長字符串大概是 1GB 。


Reference


  1. PostgreSQL Document - C8.Data Types, 8.3 Character Types, http://www.postgresql.org/docs/current/interactive/datatype-character.html



http://topic.csdn.net/t/20060120/09/4526701.html
http://phorum.study-area.org/index.php?topic=45268.0
Comments