kdbq

How to write KDB query output to a text file


filePath:hsym `$("/c/d/f/a.txt");
.co.fileHandle: hopen filePath;
x:select a,c from tab
neg[.co.fileHandle]  x

neg[.co.fileHandle] x >> is throwing type: Mismatched types errors

I am aware that I can directly save it as `:/c/d/f/x.txt. But, after writing query output to a.txt I want to add output of other queries also.


Solution

  • That only allows for a string or lists of strings to be appended to the file. Can use .Q.s to convert your table to strings.

    q)neg[.co.fileHandle] .Q.s x
    

    Can then verify the file contains the output

    > cat /c/d/f/a.txt
    a c
    ---
    1 a
    2 b
    3 c