0

I'm accessing a Teiid VDB and doing some queries, but I don't know how to generate a file with the contents of a single variable defined in a PL script:

BEGIN
    DECLARE string csvLine = '';
DECLARE string csvFile = 'C:/queryResults.csv';
LOOP ON (select user_id
FROM VBL.users
WHERE username like '%SYSTEM%' AS mycursor
  BEGIN
      LOOP ON (SELECT user_id, order_id, date, qty, price FROM VBL.orders
              WHERE user_id = mycursor.user_id
              ) as yourcursor
      BEGIN
        csvLine = csvLine || yourcursor.user_id || ',' || yourcursor.order_id || ',' || 
                  yourcursor.date || ',' || yourcursor.qty ',' || yourcursor.price || '\n';

        --- CODE to save csv_line to a file ----

      END
  END
END;

I would like to write a code like below:

 IF (fileexists(csvFile)) THEN
         fileappend(csvFile, csvLine);
 ELSE
         filewrite(csvFile, csvLine);
 END IF;

Does anyone know how to do it?

Thanks!

Renata Mesquita
  • 105
  • 1
  • 13

0 Answers0