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
2
votes
1 answer

kdb joining (concatenating) tables with repeating columns

I would like to join (concatenate) 2 or more, KDB tables which have repeating columns: d1:`a`b`c!(1 2 3;4 5 6;7 8 9) d2:`a`b`c`a!(10 20 30;40 50 60;70 80 90;100 110 120) t1: flip d1 a b c ----- 1 4 7 2 5 8 3 6 9 t2: flip…
cliff
  • 43
  • 1
  • 3
2
votes
1 answer

Integer conversion to given base

I want to convert any positive integer to some base from 2 to 9. The output for base 2should be: 0 -> enlist 0 1 -> enlist 1 31 -> 1 1 1 1 1 62 -> 1 1 1 1 1 0 63 -> 1 1 1 1 1 1 64 -> 1 0 0 0 0 0 0 I developed the next function for…
Anton Dovzhenko
  • 2,399
  • 11
  • 16
2
votes
4 answers

How to deal with symbol containing minus sign in KDB?

I got an annoying problem. We got stock symbol AGN-A in kdb+ database, but it seems almost impossible to query if this symbol is in a symbol list. The following query does not work at all: `$"A-o" in (`$"A-o";`R) Any idea how to solve this…
2
votes
1 answer

Importing CSV into KDB table

I have a csv file with random data that I can import into a table but is it possible to create columns for that table while I import the csv I tried this but it doesn't seem to work it gets a type error: details:`time`place`cost`total`address…
user3043724
  • 51
  • 1
  • 6
2
votes
1 answer

[Q/KDB+]: waitfor (wait for a signal or timeout) implementation in q

How would a q implementation of Windows' waitfor look like? I have a q process that feeds rows of a table, one at a time, to another process (say tickerplant). feed:{h`.u.upd,x;}; feed each tbl; I'd like to feed the next row if any one of the…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
2
votes
2 answers

kdb/q update multiple different values in one column for different key in keyed table

I have a table, which is : t:([alpha:`a`b`c`d`e`f];beta:10 20 30 40 50 60) I also have two variable: chgkey:`b`c chgvalue:2000 -1000 I want to do something like: t:update beta:2000 from t where alpha=`b; t:update beta:-1000 from t where…
sxzhangzsx
  • 65
  • 9
2
votes
2 answers

Saving all tables,variables, and functions of a KDB+ instance and then reloading

Is there a simple way to save all tables,variables and fucntions and then reload them into another kdb+ instance? For example, lets say my machine is set to restart weekly but I want reload everything that was in my kdb+ session before the…
Rtrader
  • 917
  • 4
  • 11
  • 26
2
votes
0 answers

qSharp ticker plant subscription

I'm currently trying to subscribe to my tickerplant using qsharp however when I try to get the message data I just get System.Int64[] to be returned or system.object[] as shown here: C# code taken from the sample: using System; using…
Rtrader
  • 917
  • 4
  • 11
  • 26
2
votes
3 answers

KDB string concatenation with symbol list for dynamic query

In this link, there is an example on how to include a dynamic parameter. d, in a KDB select query: h: hopen`:myhost01:8012 // open connection d: 2016.02.15 // define date var symList: `GBPUSD`EURUSD h raze "select from MarketDepth where date=",…
Zhubarb
  • 11,432
  • 18
  • 75
  • 114
2
votes
1 answer

KDB+ / Q table creation with foreign key

My question is about creating a table with q and using foreign keys. I know how to do it the following way q)T1:([id:1 2 3 4 5]d1:"acbde") q)T2:([id:1 2 3 4 5]f1:`T1$2 2 2 4 4) But now lets say I want to create the table with the ! operator…
Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57
2
votes
1 answer

KDB+ / Q unique random values with variable for amount

I am quite new to KDB+ and have a question about generating random numbers. Lets say I want to create num random unique numbers. When i use this q)10?10 q)-10?10 I get 10 random numbers in line 1 and 10 unique random numbers in line 2 (range from 0…
Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57
2
votes
2 answers

type char to type num mapping

q)type variable returns the type num of the arguement variable. Is there a mapping that can produce the type char from a type num or do I have to create that dictionary myself? Ideally something like q)typeChar 1 i
nightTrevors
  • 639
  • 4
  • 11
  • 24
2
votes
3 answers

kdb+/q: Check if argument has been supplied to the function call

Say we have function fun with two arguments, second one is optional. How to check within the function whether the second, optional argument has been supplied and act accordingly? fun: {[x;optarg] $["optarg was supplied" like "optarg was…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
2
votes
1 answer

Passing pandas DataFrame containing string column to kdb+ (using qPython API)

exxeleron/qPython module allows to send the pandas DataFrame to kdb+/q's table. Let's prepare the data: import pandas.io.data as web import datetime import numpy start = datetime.datetime(2010, 1, 1) end = datetime.datetime(2015, 2, 6) f =…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
2
votes
3 answers

How to get range of elements in a list in KDB?

For example, I have this list: test:(8;12;15;19;10) How may I select elements 2 to 4? When I try list[2;4] it doesn't work for me.
user3914448
  • 469
  • 1
  • 11
  • 22