0

I am totally new to q-language, but I need to use it in order to access a kdb server to get the data from.

I am using Python 3.8, under Windows10, with qPython installed.

I have trouble getting the query to the server.

from qpython import qconnection
import pandas as pd


tbl = 'q("h\"select from trade where date = 2007.02.28, sym = `XXXX\"")'


q = qconnection.QConnection(host=server, port=server_port, username=user, password=server_password, timeout=server_timeout)

q.open()
df = pd.DataFrame(q.sendSync('tbl'))
q.close()

On executing the script it returns an error at line 15:

qpython.qtype.QException: b'tbl'

So I have a trouble sending the correct expression to the server. I was able to pass the expression via terminal, using q (with PyQ) under Linux Debian 10, so the query is correct.

(The server details are skipped, as well as the bond name).

1 Answer 1

1

PyQ and qPython are being confused here. q.sendSync('tbl') will get the variable tbl from the kdb server. This error: qpython.qtype.QException: b'tbl' means tbl doesn't exist on the kdb server. I think what you wanted is the select statement to be sent to the kdb server:

from qpython import qconnection
import pandas as pd

q = qconnection.QConnection(host=server, port=server_port, username=user, password=server_password, timeout=server_timeout, pandas=True)

q.open()
df = q.sendSync('select from trade where date = 2007.02.28, sym = `XXXX')
q.close()

It might be worth while for you to spend sometime with q itself and get up to speed with some basics here:

https://code.kx.com/q4m3/1_Q_Shock_and_Awe/

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you so much about the fix with the query. And even more I thank you about the link. (I actually had seen it in the past, but I thought I would not need to learn Q language in details, as I need just the query.) I have printed df. However I see all the numbers are quite strange. The date for example is listed as '2615'... and all the rest: time, etc.
import datetime from datetime # if your kdb table has dates and times from my previous answer
from qpython import qconnection import pandas as pd from datetime import datetime Still the date and time is not good looking.
add , pandas = True to qconnection.QConnection. Seems to work for me. May not even need pd.DataFrame

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.