TEXTTABLE
The TEXTTABLE function processes character input to produce tabular output. It supports both fixed and delimited file format parsing. The function itself defines what columns it projects. The TEXTTABLE function is implicitly a nested table and may be correlated to the preceding FROM clause entries.
Usage
TEXTTABLE(expression [SELECTOR string] COLUMNS <COLUMN>, ... [NO ROW DELIMITER | ROW DELIMITER char] [DELIMITER char] [(QUOTE|ESCAPE) char] [HEADER [integer]] [SKIP integer] [NO TRIM]) AS name
Where <COLUMN>
COLUMN := name (FOR ORDINALITY | ([HEADER string] datatype [WIDTH integer [NO TRIM]] [SELECTOR string integer]))
This function has the following parameters:
To view the full table, click the expand button in its top right corner
Parameter  | Description  | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
  | Text content to process, should be convertible to   | ||||||||||||
  | Specifies that delimited lines should only match if the line begins with the selector string followed by a delimiter. The selector value is a valid column value. If a   | ||||||||||||
  | Indicates that fixed parsing should not assume the presence of newline row delimiters  | ||||||||||||
  | Sets the row delimiter/new line to an alternate character. Default: new line character with built-in handling for treating the carriage-return new line as a single character. If   | ||||||||||||
  | Sets the field delimiter character to use. Default:   | ||||||||||||
  | Sets the quote (or qualifier) character used to wrap field values. Default:   | ||||||||||||
  | Sets the escape character to use if no quoting character is in use. This is used in situations where the delimiter or newline characters are escaped with a preceding character, e.g.   | ||||||||||||
  | Set for the   | ||||||||||||
  | Specifies the number of text lines (counting every new line) to skip before parsing the contents.   | ||||||||||||
  | This column is typed as an integer and will return the 1-based item number as its value  | ||||||||||||
  | Indicates the fixed-width length of a column in characters, not bytes. With the default   | ||||||||||||
  | When specified on the   | ||||||||||||
  | |||||||||||||
  | Failed lines are written into the named table using the following format: 
  | 
Syntax Rules
If width is specified for one column it must be specified for all columns and be a non-negative integer;
If width is specified, then fixed-width parsing is used, and
ESCAPE,QUOTE,SELECTOR, andHEADERshould not be specified;If width is not specified, then
NO ROW DELIMITERcannot be used;The columns names must contain no duplicates;
QUOTE,DELIMITER, andROW DELIMITERmust all be different characters.
Examples
1. Use of the HEADER parameter, returns 1 row ['b']:
SELECT * FROM TEXTTABLE(UNESCAPE('col1,col2,col3\na,b,c') COLUMNS col2 string HEADER) x
2. Use of fixed width, returns 2 rows ['a', 'b', 'c'], ['d', 'e', 'f']:
SELECT * FROM TEXTTABLE(UNESCAPE('abc\ndef') COLUMNS col1 string width 1, col2 string width 1, col3 string width 1) x
3. Use of fixed width without a row delimiter, returns 3 rows ['a'], ['b'], ['c']:
SELECT * FROM TEXTTABLE('abc' COLUMNS col1 string width 1 NO ROW DELIMITER) x
4. Use of the ESCAPE parameter, returns 1 row ['a,', 'b']:
SELECT * FROM TEXTTABLE('a:,,b' COLUMNS col1 string, col2 string ESCAPE ':') x
5. As a nested table:
SELECT x.* FROM t, TEXTTABLE(t.clobcolumn COLUMNS first string, second date SKIP 1) x
6. Use of SELECTORs, returns 2 rows ['c', 'd', 'b'], ['c', 'f', 'b']:
SELECT * FROM TEXTTABLE(UNESCAPE('a,b\nc,d\nc,f') SELECTOR 'c' COLUMNS col1 string, col2 string, col3 string SELECTOR 'a' 2) x
7. Use of an escaped literal to set specific chars as column and row delimiters (here: carriage return as column delimiter and line feed as row delimiter) whilst reading a CSV file from the local file system:
SELECT
"csv_table".* 
FROM (CALL "ds_file".getFiles('planets_export.csv')) f,
	TEXTTABLE(to_chars(f.file,'utf-8') 
		COLUMNS 
		"id" STRING
		, "name" STRING
		, "population" STRING
		, "diameter" STRING
		, "gravity" STRING
		ROW DELIMITER E'\n'
		DELIMITER E'\r'
		QUOTE '"' 
		MAXWIDTH 8000
		SKIP 1
	)
"csv_table";;
8. Specifying any Unicode character as a delimiter with referencing their number. Same case as above but different implementation:
SELECT
"csv_table".* 
FROM (CALL "ds_file".getFiles('planets_export.csv')) f,
	TEXTTABLE(to_chars(f.file,'utf-8') 
		COLUMNS 
		"id" STRING
		, "name" STRING
		, "population" STRING
		, "diameter" STRING
		, "gravity" STRING
		ROW DELIMITER E'\u000A'
		DELIMITER E'\u000D'
		QUOTE '"' 
		MAXWIDTH 8000
		SKIP 1
	)
"csv_table";;
See Also
Using TEXTTABLE to Implement SPLIT / SPLIT_PART for a guide on how to split large strings into columns based on a delimiter