Saturday, November 14, 2015

1.27 Using the CURRENT_LOAD_SOURCE() Function to load the source file name

Using the CURRENT_LOAD_SOURCE() Function to load the source file name

When you include the CURRENT_LOAD_SOURCE function as a part of the COPY statement, the input file name or value computed from it, can be inserted into a column.

  • If the function is called outside of the context of a COPY statement, it returns NULL.
  • If the function is called by a UDL that does not set the source, it returns the string <unknown>.

I tried using this function while loading using COPY LOCAL , but it does not give the actual file Name.
Instead it just says "Batch No. 1".
This function probably works only with mutlinode loads like "ON ANY NODE" or "ON NODENAME".
Unfortunately i cannot test that. :(


Following is the example i used.

sukul1=> COPY USER_30_DAY_TABLES.EMPTABLE
sukul1-> (FIRSTNAME,
sukul1(> LASTNAME FILLER VARCHAR(20),
sukul1(> INITIALS AS SUBSTR(LASTNAME,1,1),
sukul1(> DAILYWAGE,
sukul1(> INPUTFILE_NAME AS CURRENT_LOAD_SOURCE())
sukul1-> FROM LOCAL '/home/sukul1/empdet.dat'
sukul1-> DELIMITER '|'
sukul1-> ABORT ON ERROR
sukul1-> DIRECT;
 Rows Loaded
-------------
           3
(1 row)

sukul1=> select * from USER_30_DAY_TABLES.EMPTABLE;
 FIRSTNAME | INITIALS | DAILYWAGE | INPUTFILE_NAME
-----------+----------+-----------+----------------
 RUTUJA    | K        |    234.11 | Batch No. 1
 SUKUL     | M        |     23.54 | Batch No. 1
 BHANU     | S        |    123.11 | Batch No. 1
(3 rows)

sukul1=>


No comments:

Post a Comment