CSV
Purpose
CSV (Comma-Separated Value Data Unloading) returns input row column values in text format separated by a user-specified delimiter character.
Syntax
where:
Syntax element … |
Specifies … |
TD_SYSFNLIB |
the name of the database where the function is located. |
NEW VARIANT_TYPE value |
a numeric or character expression. NEW VARIANT_TYPE can support up to 8 row column values. Each row column value can have a maximum of 128 columns of any supported data type. |
delimit_string_value |
a character expression. A comma (,) is the default delimiter character. |
quote_string_value |
a character expression. If you specify a quotation mark character, for example ‘”’, then columns defined as string data types are returned within quotation marks. |
ANSI Compliance
This is a Teradata extension to the ANSI SQL:2011 standard.
Invocation
CSV is an embedded services system function. For information on activating and invoking embedded services functions, see “Embedded Services System Functions” on page 24.
Argument Types and Rules
Expressions passed to this function must have the following data types:
Note: value cannot be CLOB or GRAPHIC.
You can also pass arguments with data types that can be converted to the above types using the implicit data type conversion rules that apply to UDFs.
Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.
For details, see “Compatible Types” in SQL External Routine Programming.
Result Type
CSV is a table function whose return value data type is VARCHAR in either the LATIN or UNICODE character set.
Example
The following query:
SELECT * FROM TABLE(CSV(NEW VARIANT_TYPE(dt.c1, dt.c2, dt.c3), ',', '"')
RETURNS (op varchar(64000) character set LATIN)) as t1;
CSV returns a string where column values are separated by commas and columns with string data types are enclosed in quotation marks.
Example
The following query:
SELECT * FROM TABLE (CSV(NEW VARIANT_TYPE(dt.c1, dt.c2, dt.c3), ',', '')
RETURNS (op varchar(32000) character set UNICODE)) as t1;
CSV returns a string where column values are separated by comma and columns with string data types are not enclosed by any characters.