The following examples illustrate the correct use of the copy statement:
ename char(15)
age integer4
dept char(10)
comment varchar(20)
The emp.txt file contains the following data:
Jones,J. 32 Anytown,USA toy,00017A comment
Smith,P. 41 New York,NY admin,00015 Another comment
The following diagram illustrates the copy statement that copies the file, emp.txt, into the employee table, and maps the fields in the file to the portions of the statement that specify how the field is to be copied. Note the following points:
A dummy column is used to skip the city and state field in the data file, because there is no matching column in the employee table.
The department field is delimited by a comma.
The comment field is a variable-length varchar field, preceded by a five-character length specifier.
copy table employee (eno=integer2, ename=char(10),
age=integer2, job=integer2, sal=float4,
dept=integer2, xxx=d1)
from 'myfile.in';
copy table employee (ename=char(0)tab,
eno=char(0)tab, sal= char(0)nl)
into 'mfile.out';
Joe Smith , 101, $25000.00
Shirley Scott , 102, $30000.00
copy table employee () into 'ourfile.dat';
copy table other_employee_table () from 'ourfile.dat';
copy table acct_recv
(acct_name=char(0)'%',
address='d0%',
credit=char(0)'%' with null('xx'),
debit=char(0)'%' with null('xx'),
acct_mngr=char(15),
nl=d1)
into 'qtr_result';
Smith Corp%% $12345.00% $-67890.00%Jones
ABC Oil %% $54321.00% $-98765.00%Green
Spring Omc%%xx %xx %Namroc
copy table gifts
(item_name=char(0)tab,
date_recd=char(0)tab,
sender=char(20)nl with null('anonymous'))
into 'giftdata';
toaster 04-mar-1993 Nicholas
sled 10-oct-1993 anonymous
rocket 01-dec-1993 Francisco
create table mytable (name char 25, ...);
modify mytable to hash;
copy mytable() from 'myfile' with minpages = 16384,
maxpages = 16384, allocation = 16384;