Import and export support functions

The import and export support functions perform any tasks needed to process external text representation of an opaque type for a bulk load and unload. When the database server copies data to or from a database in external text format, it calls the following support functions for every value copied to or from the copy file:
  • The import function imports text data by converting from external text representation to the internal format.
  • The export function exports text data by converting from the internal format to the external text representation.

These support functions do not have to be named import and export, but they do have to perform the specified conversions. They should be reciprocal functions; that is, the import function should produce a value that the export function accepts as an argument and vice versa.

The import and export functions can take special actions on the values before they are copied. Typically, only opaque data types that contain smart large objects have import and export functions defined for them. For example, the export function for such a data type might create a file on the client computer, write the smart-large-object data from the database to this file, and send the name of the client file as the data to store in the copy file. Similarly, the import function for such a data type might take the client filename from the copy file, open the client file, and load the large-object data from the copy file into the database. The advantage of this design is that the smart-large-object data does not appear in the copy file; therefore, the copy file grows more slowly and is easier for users to read.

For small opaque data types, you do not usually need to define the import and export support functions. If you do not define import and export support functions, the database server uses the input and output functions, respectively, when it performs bulk copies.

For large opaque data types, the data that the input and output functions generate might be too large to fit in the file or might not represent all of the data in the object. To resolve this problem, you can use the import functions filetoclob() and filetoblob() and the export function lotofile().