5. Populating Tables : Formatted Copying : Copy Data into a Formatted File : Data with Fixed-Length Fields
 
Share this page                  
Data with Fixed-Length Fields
Fixed-length fields can use implicit or explicit specification of the field length.
For COPY INTO, if you use the (0) notation for character or byte data, a fixed length is implicitly specified. For example, if you use char(0), character columns are copied into the file using the full display length of the column. The one exception to this rule is text(0), which exports variable width data with no padding.
Columns containing numeric data (such as integer or float data types) can be explicitly formatted using the -i or -f SQL option flags. For details on these flags, see the sql command description in the Command Reference Guide.
If you use a length specifier, the field length is explicit. For example, for char(n), the COPY INTO statement stores exactly n characters. Excess characters are discarded and shorter columns are padded with blanks.
Some forms, such as varchar(n), stores exactly n characters with a leading length indicator in ASCII format. The length indicator is the exact length of the table value without padding. After the length and value, the field is padded out to the field width n. Thus, the field width in the file is fixed; but the data can be reloaded as variable width data, since each value carries its own length indicator. These formats are called "counted" formats; see the COPY details in the SQL Reference Guide.