LOAD_FILE()¶
The LOAD_FILE() function is used to read the contents of the file pointed to by the datalink type.
Function description¶
The LOAD_FILE() function is used to read the contents of the file pointed to by the datalink type.
Note
When using load_file() to load a large file, if the file data volume is too large, the system memory limit may be exceeded, causing memory overflow. It is recommended to use it in combination with offset and size of DATALINK.
Function syntax¶
>LOAD_FILE(datalink_type_data);
Parameter explanation¶
Parameters |
Description |
|---|---|
datalink_type_data |
datalink type data can be converted using the cast() function |
Example¶
The following example writes a file with SAVE_FILE() and then reads it back with LOAD_FILE() through both a file:// URL and a stage:// URL:
DROP DATABASE IF EXISTS load_file_demo;
CREATE DATABASE load_file_demo;
USE load_file_demo;
DROP STAGE IF EXISTS stage1;
CREATE STAGE stage1 URL='file:///tmp/load-file-demo/';
remove files from stage if exists 'stage://stage1/t1.csv';
SELECT save_file(CAST('stage://stage1/t1.csv' AS datalink), 'this is a test message');
CREATE TABLE t1 (col1 int, col2 datalink);
INSERT INTO t1 VALUES (1, 'file:///tmp/load-file-demo/t1.csv');
INSERT INTO t1 VALUES (2, 'stage://stage1/t1.csv');
SELECT col1, load_file(col2) FROM t1;
SELECT load_file(CAST('file:///tmp/load-file-demo/t1.csv' AS datalink));
SELECT load_file(CAST('stage://stage1/t1.csv' AS datalink));
DROP STAGE IF EXISTS stage1;
DROP DATABASE load_file_demo;