Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to write a functional form in KDB+/Q with a present wildcard inside where clause?

As an example in a normal qSQL query we would write:

select from table where sym like "temp*"

To select any elements in the `sym column that start with "temp*" followed by any sequence of characters.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How would we write that in a functional form? It is purely for an assignment task that I’m completing which it requires me to re-write a function using functional form.

?[trade; enlist(like;`newCol;($:;enlist`ABC)); 0b; ()] this works well in the KX Academy Jupyter Notebook however, this does not take a wildcard into consideration.

My parsed select statement returns me this:

?
`table
,,(';(like;`sym);(*;`temp))
0b
()

However, I’m failing to understand how to write this, there’s nothing I could find online. Please help.

>Solution :

When building your query you can use backslashes to escape the quote characters to allow your query to be parsed:

q)parse "select from table where sym like \"temp*\""
?
`table
,,(like;`sym;"temp*")
0b
()

which would be formed into:

?[table;enlist (like;`sym;"temp*");0b;()]

There is a nice script by kx which helps in forming functional selects:

https://code.kx.com/q/wp/parse-trees/#appendix

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading