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
3
votes
3 answers

Pascal's triangle in k/q

fibonacci is nice: f:|+\ 5 f\1 1 but i haven't found a similar expression for Pascal's Triangle. this is the best i can get: q){x+\\x#1}6 1 1 1 1 1 1 1 2 3 4 5 6 1 3 6 10 15 21 1 4 10 20 35 56 1 5 15 35 70 126 1 6 21 56 126…
effbiae
  • 1,087
  • 1
  • 7
  • 22
3
votes
3 answers

Take a column of a matrix and make it a row in kdb

Consider the matrix: 1 2 3 4 5 6 7 8 9 I'd like to take the middle column, assign it to a variable, and replace the middle row with it, giving me 1 2 3 2 5 8 7 8 9 I'm extracting the middle column using a:m[;enlist1] which returns 2 5 8 How do…
Jonathan
  • 109
  • 6
3
votes
1 answer

Calculate minimum and maximum values of each variable in a table in kdb

Consider the following table: sym A B X 1 2 Y 4 1 X 6 9 Z 6 3 Z 3 7 Y 1 8 I want to find the minimum A value and maximum B value for each of my symbols X, Y & Z and display them in a new table, i.e. sym minA maxB X 1 9 Y 1 8 Z…
Jonathan
  • 109
  • 6
3
votes
2 answers

Store a column as a string in kdb

I have a table with numerous columns. I'm trying to take the data from one of the columns and return it as a string. For instance, if I had: A B C 1 2 3 4 5 6 7 8 9 I would like to take column B and store 258 as a string. How would I do this?
Jonathan
  • 109
  • 6
3
votes
3 answers

[KDB+/Q]: Nested vector conditional

How to efficiently and concisely switch formulas dependent on the value of other vector? According to kx documentation, it is possible to have more than just a true/false selection, e.g. match1/match2/match3/others mapping to…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
3
votes
1 answer

What is the q @ symbol doing in the context of being applied as a function call?

What is going on in the example here? Source: http://code.kx.com/q/ref/select/#index-at @[d;1 1 1;+;3] ((1 2 3;4 5 6 7);(17 18;19;20 21);(13 14;15 16 17 18;19 20))
user7613376
3
votes
2 answers

How to delegate user query to a separate thread in KDB/Q

Is there a way in KDB/Q to delegate user request to a separate thread? In my server, I have an internal calculation loop that runs at frequent intervals and takes time to finish. While it is running, all user queries are blocked. How do I delegate…
user236215
  • 7,278
  • 23
  • 59
  • 87
3
votes
2 answers

How to export every table to csv in a kdb+ database?

Assume my kdb+ database has a few tables. How can I export all tables to csv files where the name of each csv is same as the table name?
Gavin Chan
  • 55
  • 8
3
votes
1 answer

How to exec against a loaded splayed table in KDB?

I have a splayed table written to disk via .Q.dpft[]. After load this table using the \l system command, I can select from this table, e.g., select column_name from splayed_table where xyz However, when I convert select to exec, I always get the…
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
3
votes
4 answers

Update value in dictionary for q lang (kdb+)

How I may update values in q dictionary use functional way? Example: x: `1`2`3; d: x!x; show[d]; // d -> // 1 | 1 // 2 | 2 // 3 | 3 // TODO change d: show[d]; // d -> // 1 | 11 // 2 | 22 // 3 | 3
Alykoff Gali
  • 1,121
  • 17
  • 32
3
votes
5 answers

How to format a Date in Q language (KDB) to MM/DD

I'm a beginner to KDB/Q Langage, and I'm looking to find a way to convert a date object (or its string representation) to the format MM/DD. For example, I have 2016-09-23 and I would like to format it to 09/23. There is another thread relating to…
Edward Cai
  • 33
  • 3
3
votes
1 answer

q interpreter not recalling history on Ubuntu 16.04

Last night I went to install q and kdb 32 bit on my system. I have been using it at work and whenever I hit the up arrow key at work it recalls the previous command. This does not seem to be working on my home install. When I hit the up it it…
chasep255
  • 11,745
  • 8
  • 58
  • 115
3
votes
1 answer

[Q/KDB+]: wsfull when creating splayed table from csv using `.Q.fs`

I have a 9.6GB csv file from which I would like to create an on-disk splayed table. When I run this code, my 32-bit q process (on Win 10, 16GB RAM machine) runs out of memory ('wsfull) and crashes after creating an incomplete 4.68GB splayed table…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
3
votes
2 answers

Adding a column based on other columns KDB+

I have a table ("ibmqt") with a number of columns, and I would like to add a new column, containing boolean values indicating for each row whether one column ("bid") is greater than or equal to another column ("ask"). My most successful attempt so…
3
votes
6 answers

How to produce a formatted date string in Q/KDB?

How can one produce an ISO date string "yyyy-MM-dd" from a Q date type? I looked at concatenating the various parts but am not even able to get the day/month, e.g. d:2015.12.01;d.month prints 2015.12, i.e. more than just the month.
ScarletPumpernickel
  • 678
  • 1
  • 7
  • 22