FCSVPARSER
Parses CSV format (comma-separated values) data. Use this parser to load CSV data into columnar, flex, and hybrid tables. All data must be encoded in Unicode UTF-8 format. The fcsvparser
parser supports the RFC 4180 standard for CSV data, and other options, to accommodate variations in CSV file format definitions. Invalid records are rejected. For more information about data formats, see Handling Non-UTF-8 input.
Syntax
FCSVPARSER ( [parameter='value'[,...]] )
Parameters
type |
The default parameter values for the parser, one of the following strings:
You do not have to use the type parameter when loading data that conforms to the RFC 4180 standard (such as MS Excel files). See Loading CSV data for the Default: |
delimiter |
A single-character value used to separate fields in the CSV data. Default: |
escape |
A single-character value used as an escape character to interpret the next character in the data literally. Default:
|
enclosed_by |
A single-character value. Use Default: |
record_terminator |
A single-character value used to specify the end of a record. Default:
|
header |
Boolean, specifies whether to use the first row of data as a header column. When If you specify Default: true |
header_names |
A list of column header names, delimited by the character defined by the parser's delimiter parameter. Use this parameter to specify header names in a CSV file without a header row, or to override the column names present in the CSV source. To override one or more existing column names, specify the header names to use. This parameter overrides any header row in the data. |
trim |
Boolean, specifies whether to trim white space from header names and key values. Default: true |
omit_empty_keys |
Boolean, specifies how the parser handles header keys without values. If true, keys with an empty value in the Default: false |
reject_on_duplicate |
Boolean, specifies whether to ignore duplicate records (false), or to reject duplicates (true). In either case, the load continues. Default: false |
reject_on_empty_key |
Boolean, specifies whether to reject any row containing a key without a value. Default: false |
reject_on_materialized_type_error |
Boolean, specifies whether to reject any materialized column value that the parser cannot coerce into a compatible data type. See Loading CSV data. Default: false |
Examples
This example shows how you can use fcsvparser
to load a flex table, build a view, and then query that view.
-
Create a flex table for CSV data:
=> CREATE FLEX TABLE rfc(); CREATE TABLE
-
Use
fcsvparser
to load the data from STDIN. Specify that no header exists, and enter some data as shown:=> COPY rfc FROM stdin PARSER fcsvparser(header='false'); Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 10,10,20 >> 10,"10",30 >> 10,"20""5",90 >> \.
-
Run the
compute_flextable_keys_and_build_view
function, and query therfc_view
. Notice that the defaultenclosed_by
character permits an escape character ("
) within a field ("20""5"
). Thus, the resulting value was parsed correctly. Since no header existed in the input data, the function addeducol
n
for each column:=> SELECT compute_flextable_keys_and_build_view('rfc'); compute_flextable_keys_and_build_view -------------------------------------------------------------------------------------------- Please see public.rfc_keys for updated keys The view public.rfc_view is ready for querying (1 row) => SELECT * FROM rfc_view; ucol0 | ucol1 | ucol2 -------+-------+------- 10 | 10 | 20 10 | 10 | 30 10 | 20"5 | 90 (3 rows)
For more information and examples using other parameters of this parser, see Loading CSV data.