split_csv¶
SPLIT_CSV
Splits a CSV buffer into rows and columns.
Parameters:
p_string (
str) – The CSV input string or an expression.p_expression (
bool) – Set to True if p_string is an expression to be evaluated.p_row_sep (
str) – Row delimiter (e.g., newline).p_col_sep (
str) – Column delimiter (e.g., semicolon or comma).p_skip_elements (
int) – Number of rows to skip (e.g., for headers).p_remove_empty_elements (
bool) – If True, empty elements will be removed.p_strict_col_count (
bool) – If True, rows with unequal column counts will raise an error.
returns: emits – Multiple columns based on the CSV structure.
raises Exception: In case of parsing or expression evaluation errors.
Examples¶
Basic CSV splitting
1select split_csv('a;b;c' || chr(10) || 'd;e;f', false, chr(10), ';', 0, false, false)
2emits (a varchar(2), b varchar(2), c varchar(2));
Splitting output from an expression
1select split_csv('get_url_data(url="https://example.com/data.csv")', true, chr(10), ';', 0, false, false)
2emits (jahr varchar(10), Auszeichnung varchar(200));
Using Regex-like column delimiters (e.g., Space or Tab)
1select split_csv('sphinx.at. 600 IN A 10.10.31.99', false, chr(10), '[' || chr(9) || ' ]', 0, true, false)
2emits (a varchar(92), b varchar(92), c varchar(92), d varchar(92));
Handling unequal column counts
1-- This will allow rows with different counts if p_strict_col_count is false
2select split_csv('a;b' || chr(10) || 'd;e;f', false, chr(10), ';', 0, false, false)
3emits (a varchar(2), b varchar(2), c varchar(2));