Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
SQL iQuery Documentation - UDF and UDTF
has no ratings.
Published: 17 Jun 2019
Revised: 20 Aug 2019 - 426 days ago
Last viewed on: 19 Oct 2020 (209 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
  12. GET CPUCNT, CURLIB, ENV, SRLNBR, SYSNAME
  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.ifsFile() UDTF Published by: Bob Cozzi on 17 Jun 2019 view comments

Query Contents of IFS File

The iQuery.ifsFile() UDF reads the specified IFS text file and returns one row for each "record" in the Text file. The basic output is similar to the DSPF CL command, but can be queried and re-directed to other formats.

The returned value is always a varchar(8192) value and my be re-cast using CAST or by wrapping the result in VARCHAR() with a different result column width. If the resulting text data is longer than 8192 characters, it is truncated.

Parameters

iQuery.ifsFile( 'IFS text file name and path' )

The IFS Text File Name and Path parameter identifies the IFS text file to be queried. This can be a plain text file, CSV file, JSON, etc. If the file is from Microsoft Windows and it contains a BOM (Byte Order Mark) IFSFILE will attempt to detect the BOM and continue to render the rest of the file normally.

ResultSet Columns

Column
Name
System
Column
Name
Data Type Description
TEXTDATA TEXTDATA varchar(8192) The IFS text file data from the IFS file. One row is returned for each "line" in the text file. 

The UDTF reads IFS text files as rows or lines. A line is everything up until a CR/LF or LF/CR pair. In addition, it also supports lines that end with a signel LF or CR symbol. Each line is returned as one row in the resultSet. 

Example

In this example, our sample COUNTRY.TXT file that contains a list of all countries followed by their abbreviation (separated by a semicolon) is queried using SQL iQuery IFSFILE() UDTF and is returned.

select * table(iQuery.ifsFile('/home/cozzi/country.txt')) text;

TEXTDATA                
COUNTRY;ABBR            
AFGHANISTAN;AF          
ÅLAND ISLANDS;AX        
ALBANIA;AL              
ALGERIA;DZ              
AMERICAN SAMOA;AS       
ANDORRA;AD              
ANGOLA;AO               
ANGUILLA;AI             
ANTARCTICA;AQ           
ANTIGUA AND BARBUDA;AG   

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

COMMENTS