1

I'm trying to create a splayed table with a symbol column using pyq. In q I would set the table by enumerating the symbol column with .Q.en...

:splay/ set .Q.en[`:splay;]([]a:`x`y`z; b:1 2 3)

I tried a few variations of the following...

q.set(':splay/', q('.Q.en')('!', ["Name", "Ask", "Bid", "Last", "Vol", "Time"], [K.symbol([]), K.float([]), K.float([]), K.float([]), K.float([]), K.timestamp([])]).flip)

But it throws the following rank error: _k.error: rank.

What is the proper syntax for this in pyq?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
marrowgari
  • 417
  • 3
  • 15

1 Answers1

3

First, your q code is incorrect. The function

.Q.en[`:splay;]

will place the sym file inside the splay table and this is not what you want. Instead, the sym file should be saved in the top database directory (db in the code below) next to the splay table.

`:db/splay/ set .Q.en[`:db]([]a:`x`y`z; b:1 2 3)

The same code can be written in pyq as

q.set(':db/splay/', q('.Q.en', ':db', q('([]a:`x`y`z; b:1 2 3)')))
Alexander Belopolsky
  • 2,228
  • 10
  • 26
  • Thanks, Alexander. That worked to create the splayed table. But I'm going to have to post a follow up question in regards to how to `q.upsert` into a splayed table because it keeps throwing an error. I'm assuming it has to do with enlisting the data I'm appending, since I'm doing it 1 row at a time. I just can't figure out the correct syntax to do this in pyq. – marrowgari Dec 19 '17 at 20:27