You can use a named pipe, also referred to as a first-in-first-out (FIFO) data file, to load from and unload to a nonstandard device, such as a tape drive.
Unlike ordinary operating-system files, named pipes do not have a 2-gigabyte size limitation. The operating system opens and checks for the end of file differently for named pipes than for ordinary files.
To use named pipes to load data from external tables, follow these steps:
Suppose you have a database server system with 16 coservers, but only 3 coservers have tape drives attached (for example, coservers 2, 5, and 9).
% onutil 1> CREATE COGROUP tape_group 2> FROM cosv.2, cosv.5, cosv.9; Cogroup successfully created.
CREATE EXTERNAL TABLE emp_ext ( name CHAR(18) EXTERNAL CHAR(20), hiredate DATE EXTERNAL CHAR(10), address VARCHAR(40) EXTERNAL CHAR(40), empno INTEGER EXTERNAL CHAR(6) ) USING ( FORMAT 'FIXED', DATAFILES("PIPE:tape_group:/usr/local/TAPE.%c") );
The filenames expand as follows:
DATAFILES ("PIPE:2:/usr/local/TAPE.2", "PIPE:5:/usr/local/TAPE.5", "PIPE:9:/usr/local/TAPE.9")
Use the mknod UNIX command with the -p option to create a named pipe. To avoid blocking open problems for pipes on UNIX, start separate UNIX processes for pipe-readers and pipe-writers or open the pipes with the O_NDELAY flag set.
The database server provides a sample pipe-reader program in $INFORMIXDIR/demo/xmp/rpipe.c and a sample pipe-writer program in $INFORMIXDIR/demo/xmp/wpipe.c.
INSERT INTO employee SELECT * FROM emp_ext;
The database server uses FIFO virtual processors (VPs) to read and write to external tables on named pipes. The NUMFIFOVPS configuration parameter specifies the number of FIFO VPs for each coserver. The default number is 2.
The database server uses one FIFO VP for each named pipe that you specify in the DATAFILES clause of the CREATE EXTERNAL TABLE statement. For example, suppose you define an external table with the following SQL statement:
CREATE EXTERNAL TABLE atab_ext SAMEAS atab USING ( DATAFILES("PIPE:1:/tmp/pipe1", "PIPE:1:/tmp/pipe2", "PIPE:1:/tmp/pipe3" ));
If you use the default value of 2 for FIFO VPs, the database server does not read from pipe3 until it finishes reading all the data from pipe1 or pipe2.
To use named pipes to unload data to external tables, follow these steps:
DATAFILES ("PIPE:tape_group:/usr/local/TAPE.%c")
The database server provides a sample pipe-reader program in $INFORMIXDIR/demo/xmp/rpipe.c and a sample pipe-writer program in $INFORMIXDIR/demo/xmp/wpipe.c.
You can use the SELECT INTO EXTERNAL statement to unload from named pipes, as the following example shows:
SELECT * FROM employee WHERE hiredate > "1/1/1996" INTO EXTERNAL emp_ext USING ( FORMAT 'DELIMITED', DATAFILES ("PIPE:2:/usr/local/TAPE.2", "PIPE:5:/usr/local/TAPE.5", "PIPE:9:/usr/local/TAPE.9") );
Alternatively, you can use the following SQL statement sequence to unload from named pipes:
CREATE EXTERNAL TABLE emp_ext ( name CHAR(18) EXTERNAL CHAR(20), hiredate DATE EXTERNAL CHAR(10), address VARCHAR(40) EXTERNAL CHAR(40), empno INTEGER EXTERNAL CHAR(6) ) USING ( FORMAT 'FIXED', DATAFILES ("PIPE:tape_group:/usr/local/TAPE.%c") ); INSERT INTO emp_ext SELECT * FROM employee;