Questions tagged [q-lang]

The q language is a programming language by kx.com for querying kdb+ databases.

Q was developed by Arthur Whitney in 2003 and is built on top of the K programming language. The names q and kdb+ are often used interchangeably, but generally q refers to the programming language and kdb+ refers to the entire runtime environment.

245 questions
1
vote
5 answers

Remove part of string KDB

I have a table named "t", with column, "x". It looks as follows: x ------ 1.Fred 2.Joe 3.Hank . . . 500.Mary I need to take the column and remove everything before the name, for example the "1." before Fred. I have tried update $2_'string x…
michaelg
  • 243
  • 2
  • 8
  • 25
1
vote
2 answers

Adding Columns in kdb based on other columns value

I have a column like this in dataframe named test: Name Client A P B Q C R D S E T I need to to create a new column clienttype in the same dataframe with condition that, if Client = P or Q clienttype = first.…
user8415577
1
vote
3 answers

functional update single value in q/kdb+

t:([] col1:`aa`bb`cc;col2:`aaa`bbb`ccc); field1:`col1; field2:`col2; v1:`aa; v2:`aaaa; I want same result by functional update as update col2:`aaaa from t where col1=`aa; I tried ![t;enlist (=;field1;enlist v1);0b;(enlist…
sxzhangzsx
  • 65
  • 9
1
vote
2 answers

[KDB+/Q]: Deparse q parse tree into q expression (string)

Let's define deparse1 as inverse operation to q's native parse, so that the following holds: q)aStringQExpression~deparse parse aStringQExpression 1b Question What's the definition of deparse function so that the above indeed works? For example,…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
1
vote
3 answers

Create a Boolean column displaying comparison between 2 other columns in kdb+

I'm currently learning kdb+/q. I have a table of data. I want to take 2 columns of data (just numbers), compare them and create a new Boolean column that will display whether the value in column 1 is greater than or equal to the value in column 2.…
Jonathan
  • 109
  • 6
1
vote
1 answer

q/kdb: How do I break my code into lines. Is there a new line 'escape' character or something similar?

I am writing long scripts on one line. I would like to organise my code by breaking code onto multiple lines without having to write a function. How do I do this?
Alim Hasanov
  • 197
  • 1
  • 3
  • 16
1
vote
2 answers

Understanding how to read each-right and each-left combined in kdb

From q for mortals, i'm struggling to understand how to read this, and understand it logically. 1 2 3,/:\:10 20 I understand the result is a cross product when in full form: raze 1 2 3,/:\:10 20. But reading from left to right, I'm currently…
user7613376
1
vote
1 answer

kdb+ How do I import only specific columns from a CSV file into a table

Example: CSV file with 4 headers: a,b,c,d. How do I only "pick" columns b & d for example, so I end up with a q table with two columns with the b & d headers?
Alim Hasanov
  • 197
  • 1
  • 3
  • 16
1
vote
2 answers

Q/KDB+: Percentile function excluding nulls

What's the least verbose way to express percentile function (not to be confused with percentile) in Q, excluding nulls? I have: q)x:0N 1 2 0N 2 1 5 q)@[count[x]#0Nf;i;:;(1%count i)*1+rank x i:where not null x] 0n 0.2 0.6 0n 0.8 0.4 1 Problem with…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
1
vote
1 answer

How do I disable the KDB+ debugger for non-interactive sessions?

Sometimes, when my q script has an error, the debugger prompt appears: q)). I need to type \ to exit the debugger. This is OK during interactive sessions, but breaks my scheduled (non-interactive) runs from crontab. Can I disable the debugger for…
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
1
vote
3 answers

Why does union join (uj) sometimes trigger "cast" error?

I am getting error 'cast when I try to union join (uj) two very simple, five row tables in KDB+. What is the cause of the error in the below code? q)t1b Symbol | RIC ---------| --------- 000001.SZ| 000001.SZ 000001.ZK| 000001.ZK 000002.SZ|…
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
1
vote
1 answer

How to get kdb handle with c.java library

I need to get address of my connection (I don't know exact name of it but it is number with 'i' char), when I want to connect to server in kdb process I just use function: q) h: hopen`:localhost:5000:username:password q) h 5i and then I know that…
dusiu
  • 31
  • 5
1
vote
2 answers

kdb/q, reserved word as column name

I have a kdb table with column name type and want to select data by a giving type. It's like: select from table where type=giving_type it issues an error of : 'type, because type is a reserved word in q. Then how to do this?
zjc
  • 11
  • 4
1
vote
1 answer

[KDB+/Q]: Reattach Windows console to a background running q process

Assuming there is q process running in the background after launching it with system command: $ q q) system "q -p 5000" q) \\ $ How can I attach my Windows console (cmd or PowerShell) or terminal multiplexer (such as ConEmu) back to that process,…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
1
vote
1 answer

Issue with null character received by qpython/pandas from kdb

This question is pretty much directed at @Maciej Lach but if anyone else has experienced this issue please let me know. The issue is simple - qpyhton crashes (when pandas is set to true) whenever kdb sends it a single row table where one of the…
terrylynch
  • 11,844
  • 13
  • 21