marrowgari
marrowgari

Reputation: 427

Upsert to a table in pyq

OS: Windows 10 Enterprise, Python: Python 3.6.4, PyQ: pyq (4.1.4).

I'm pretty certain my data types are correct, though I keep receiving _k.error: type when I attempt to upsert to my table.

First I initialize the table with the following command...

q.set(':testTable', q('!', ["Key", "Status", "Descr", "FileName"], [K.long([]), K.int([]), K.char([]), K.symbol([])]).flip)

Check the table meta...

q.get(':testTable').meta.show()
c       | t f a
--------| -----
Key     | j
Status  | i
Descr   | c
FileName| s

I set some sample variables in python and store them in a list and a dictionary respectively...

key = 42
status = 3
descr = "h"
fn = "cymbeline"
data = [key, status, descr, fn]
data_dict = {a:b for a, b in zip(['Key', 'Status', 'Descr', 'FileName'], data)}

Then I try to upsert to the table, using each of the below commands separately...

q.upsert(':testTable', data)
q.upsert(':testTable', data_dict)

However, they both fail with the same _k.error: type message.

I assume there's a simple solution here but I can't seem to figure it out. Thank you in advance.

Upvotes: 0

Views: 150

Answers (1)

Alexander Belopolsky
Alexander Belopolsky

Reputation: 2268

You need to explicitly cast descr to K.char type:

descr = K.char("h")

otherwise it will be implicitly converted to a symbol and you will get a type error.

Upvotes: 1

Related Questions