The eXtremeSQL character data types provide fixed length and variable length storage options for arrays of single-byte (e.g. ascii) or double-byte (e.g. unicode) characters. The size of character arrays cannot exceed 64 Kb. For fields that must store more than 64 Kb of data, a BLOB can be used.
For an overview see page SQL Data Types
Fixed Length Character Fields
Fixed length character arrays must be declared with a specified length: such as
CHAR(n),VARCHAR(n),LONGVARCHAR(n)orUNICODE(n). (Note that data type names are not case sensitive; i.e.CHARandcharare equivalent). For example, the following statement creates a table with two fixed length character fields:create table t( c char(30), u unicode(30) );The amount of storage space allocated for fixed length character arrays is the specified number of bytes for
CHAR(n)but two times the specified length for UNICODE(n). For example, the following Metatable query shows the actual storage allocation for the declaration above:select FieldName, FieldSize from Metatable where TableName = 't'; FieldName FieldSize ---------------------------------------------------------------------- c 30 u 60The storage for a single field cannot exceed 64 Kb (65,536 bytes). Some additional bytes of overhead are required for each database field. Thus, the maximum length
nfor aCHAR(n)declaration is65527; and forUNICODE(n)the maximum value fornis32763.If character data longer than the fixed length of a
CHAR(n)field is inserted, the value stored is truncated to the declared length. For example:create table t(c char(3), u unicode(3)); insert into t values('1234567', '1234567'); select * from t; c u ------------------------------------------- 123 123Variable Length Character Fields
Variable length character arrays are declared by not specifying a length for
CHARorUNICODEtypes or by declaring the field of typeVARCHAR,LONGVARCHARorSTRING. In fact,LONGVARCHARandSTRINGare effectively aliases forVARCHAR. All variable length character arrays are mapped internally to the eXtremeDBstring(single-byte) andnstring(double-byte) types; the Metatable asFieldTypeNameisStringorUnicode. For example, in the following table definition, all of the field declarations are equivalent:create table t(c char, v varchar, lv longvarchar, s string); select FieldName, FieldTypeName, FieldSize from Metatable where TableName = 't'; FieldName FieldTypeName FieldSize ------------------------------------------------------------------------------ c String 0 v String 0 lv String 0 s String 0Note that the
FieldSizeof0indicates that no storage is allocated for variable length fields (apart from the 2 or 4 byte address of the variable sized storage) until values are actually inserted.(See page Base Data Types for further details.) And, as for fixed length
UNICODEfields, variable lengthUNICODEfields store double-byte character arrays. Note the difference in theFieldSizein the following declaration:create table t2( u unicode(30), uv unicode); select FieldName, FieldTypeName, FieldSize from Metatable where TableName = 't2'; FieldName FieldTypeName FieldSize ------------------------------------------------------------------------------ u Unicode 60 uv Unicode 0