Midrange News for the IBM i Community

Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
SQL iQuery Documentation - UDF and UDTF
has no ratings.
Published: 10 Jun 2019
Revised: 20 Jun 2019 - 487 days ago
Last viewed on: 19 Oct 2020 (1454 views) 
  1. SQL iQuery - RUNiQRY CL Command
  2. CSV() - Read and Parse Comma Separated Values File
  3. CSV_VAL() Extract CSV Column Value
  4. CSV_XXXX() Extract CSV Column Value as xxxx
  5. CSV_COUNT - Retrieve Field Count
  6. ObjExist - Check Object Exits
  7. DTAARA - Data Area
  8. encode_URL Encode URL for the Web
  9. encode_TAG Encode HTML TAG Content
  10. FLDLIST - List the Fields of a Table
  11. FROMHEX - Fold 2-hex Chars into 1 Char
  13. MD5_HASH - UDF - Return MD5 Hash
  14. ifsStat - Get IFS File Attributes
  15. ifsExists - Check if IFS File Exists
  16. ifsFile - Query Contents of IFS Text File
  17. ifsDIR - List IFS Directory Entires
  18. DEPFILE - List Dependent Database Relations
  19. JOB - Get Job Name Component
  20. Job_ATTR - Job Attributes
  21. JOB_DATE Retrieve the Job Date
  22. JOBLOG - Write Message to Joblog
  23. Library List UDF and Procedures
  24. MBRLIST - Member List
  25. MCHINFO Machine Type and Model Number and OS version
  26. OSVER and OSVRM Get IBM i Version/Release
  27. PrintPDF - Print a PDF to a PDF Compatible Printer
  28. CPYTOPDF - Copy SPOOLED File to PDF file
  29. OBJ_LIST List Object in a Library
  30. LIB_LIST List Descriptions of Libraries on the Library List
  31. OBJ_EXPORTS List Exported Items from an Object
  32. OBJ_STRUCT Retrieve Objects Components
  33. RTVCMDD Retrieve Command Definition
  34. RTVJOBA - Retrieve Job Attributes
  35. RTVJOBD - Retrieve Job Description
  36. RTVLASTSPLF - Retrieve ID of Last SPOOLED File for this Job
  37. RTVxxx - Retrieve Various Objects Description Table Functions
  38. WATCHLIST - List Current Watches
  39. Polymorphic Qualified Name Syntax

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

iQuery.CSV() UDTF Published by: Bob Cozzi on 10 Jun 2019 view comments

Read CSV File

The iQuery.CSV() UDTF reads an IFS text file that contains Comma Separated Values and returns that contant to the caller. The data can be extracted using the provided iQuery.csv_val() function or one of the variations of it to return decimal, text, date/time or integer content.

The maximum width of a CSV result cannot exceed about 8k (8192 bytes).


iQuery.csv( 'ifs-file-and-path', [number of header rows: dft 1], [ dump column names] )

The IFS file and path is a classic IFS file name with the fully qualified path name. If no path is specified and only a file name is used, it uses the current working directory to locate the file. It is normally recommended to fully qualify the file name to the path in which it is located.

The optional number of header rows indicates to the UDTF how many row were used to generate the CSV column headings (if any). By default 1 row is assumed.  The column headings may be used to reference the columns using the CSV_VAL() and related functions. If no column headings are included in the CSV file, then specify 0 for this parameter, and refer to the columns on the CSV_VAL() function by the relative column number only.

The optional dump column name parameter may be used to generate a list of CSV column names to the joblog. This can help with debugging certain files when the column name is not working as expected. Typically this is rarely used an is only inteded for debug purposes.

Data Type Description
DATA DATA VARCHAR(8192) The CSV data is parsed and returned as a fixed width record. Use this columin the CSV_VAL() UDF to extract the data from the result set using either column names or relative column number. 


select csv_val(data,'custno'), csv_val(data,'custName') from iQuery.csv('/home/pickles/customers.csv');

In this example, the CUSTNO and CUSTNAME columns from the CSV file named CUSTOMERS.CSV are returned. The file is located in folder /home/pickles on the IFS. The data is returned as text. To return the CUSTNO colum as numeric, use CSV_DEC or CSV_INT functions.


Return to midrangenews.com home page.
Sort Ascend | Descend