TEXTTABLE
関数は、文字入力を処理して表形式の出力を生成します。固定ファイル形式と区切りファイル形式の両方の解析をサポートしています。関数自身が、どの列を投影するかを定義します。TEXTTABLE
関数は暗黙的にネストされたテーブルであり、先行するFROM
Clause 項目に相関している可能性があります。
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
]))
この関数には以下のパラメータがあります:
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
- widthが1つの列に指定された場合、それはすべての列に指定されなければならず、非負の整数でなければなりません;
- widthが指定されている場合、固定幅の構文解析が使用され、
ESCAPE
、QUOTE
、SELECTOR
、HEADER
は指定されるべきではありません; - width が指定されていない場合、
NO ROW DELIMITER
; - カラム名には重複があってはなりません;
QUOTE
,DELIMITER
,ROW DELIMITER
はすべて異なる文字でなければなりません。
Examples
1. HEADER
パラメータを使用すると、1 行 ['b'] が返されます:
SELECT
*
FROM
TEXTTABLE(UNESCAPE(
'col1,col2,col3\na,b,c'
) COLUMNS col2 string HEADER) x
2. 固定幅を使用し、2行 ['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. 行区切り文字なしで固定幅を使用すると、3行 ['a'], ['b'], ['c'] が返されます:
SELECT
*
FROM
TEXTTABLE(
'abc'
COLUMNS col1 string width 1
NO
ROW DELIMITER) x
4. ESCAPE
パラメータを使用すると、1 行 ['a,', 'b'] を返します:
SELECT
*
FROM
TEXTTABLE(
'a:,,b'
COLUMNS col1 string, col2 string
ESCAPE
':'
) x
5. ネストされたテーブルとして:
SELECT
x.*
FROM
t, TEXTTABLE(t.clobcolumn COLUMNS
first
string,
second
date
SKIP 1) x
6. SELECTOR
s を使用すると、2 行 ['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. ローカル・ファイル・システムから CSV ファイルを読み込む際に、エスケープされたリテラルを使用して、特定の文字を列と行の区切り文字として設定します(ここでは、キャリッジ・リターンを列の区切り文字として、ライン・フィードを行の区切り文字として設定します):
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. 任意の Unicode 文字を、その番号を参照しながら区切り文字として指定します。上記と同じCASEですが、実装が異なります:
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 デリミタに基づいて大きな文字列をカラムに分割する方法 については、こちらをご覧ください。