John Dempster - John Dempster

Forum Replies Created

Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • in reply to: string functions? like search replace regex? #520

    John Dempster
    Keymaster

    When selecting based on the condition of a string or char array column, “like” is normally used.

    The verb like takes two arguments
    1. The list of strings to search
    2. The pattern to be searched for
    The pattern has certain meta characters like *,? and [] that allow pattern matching.
    However full regular expressions are not supported.

    Here are some examples:

    q)t:([] a:til 6; name:(“John Smith”;”John Doe”;”Kate Beck”;”George Bush”;”Isaac Asimov”; “Dave Beck”))
    q)t
    a name
    —————-
    0 “John Smith”
    1 “John Doe”
    2 “Kate Beck”
    3 “George Bush”
    4 “Isaac Asimov”
    5 “Dave Beck”

    / perfect matches, rely on correct case
    q)select from t where name like “John Smith”
    a name
    ————–
    0 “John Smith”
    q)select from t where name like “John smith”
    a name
    ——

    / * – matches any number of characters
    q)select from t where name like “John*”
    a name
    ————–
    0 “John Smith”
    1 “John Doe”

    / ? – Represents any single character
    q)select from t where name like “???? Beck”
    a name
    ————-
    2 “Kate Beck”
    5 “Dave Beck”

    / [] – square brackets contain allowed character sets
    q)select from t where name like “John [S]*”
    a name
    ————–
    0 “John Smith”

    q)select from t where name like “John [SD]*”
    a name
    ————–
    0 “John Smith”
    1 “John Doe”

    Here we used it to match a table with a string column, you can use it on a plain list of strings or symbols as well.

    Regards,
    John

    in reply to: Are there seminars and conferences for kdb+ ? #444

    John Dempster
    Keymaster

    KX regularly hold workshops internationally: http://www.kx.com/events-kx.php
    We provide free kdb+ tutorials for learning kdb: http://www.timestored.com/kdb-guides
    We can come deliver a training course at your company: http://www.timestored.com/kdb-training
    There are two mailing lists, a few linkedin groups

    Best way to learn is to go through q for mortals, our free tutorials then try and use it to solve an actual problem you have or make up one.

    Best of luck.

    -JD

    in reply to: curly brackets mean what in kdb+q? #443

    John Dempster
    Keymaster

    Curly brackets contain a function. e.g.
    {x+1}
    would be a function that adds one to it’s argument.

    {[a] b:a*10; b}
    In this function we have named the argument a
    Created a variable b which is ten times a
    and returned that vlue (Since it’s the last statement)

    {} is only used to contain function bodies there is no other use in kdb.

    in reply to: show tables in kdb+ #442

    John Dempster
    Keymaster

    \a or system “a” will list all the tables that exist on the kdb+ server.

    q)t:([] a:1 2 3)
    q)\a
    ,`t
    q)system “a”
    ,`t
    q)t2:([] c:4 5)
    q)\a
    `s#`t`t2
    q)system “a”
    `s#`t`t2

    in reply to: rank error during select x y z from table #260

    John Dempster
    Keymaster

    It is a bug. q has issues with default parameters and qsql queries inside function. You can see this from the code below:

    `q)t:([] a:1 2 3 4 5; b:6 7 8 9 0)
    q)t
    a b

    1 6
    2 7
    3 8
    4 9
    5 0`

    One parameter works
    `
    q){select from t where a in x}[2 3]
    a b

    2 7
    3 8`

    Two parameters fail.
    `
    q){select from t where a in x,b in y}[2 3;6 7]
    ‘rank
    `

    Notice when I name the parameters the function executes successfully.
    `
    q){[x;y] select from t where a in x,b in y}[2 3;6 7]
    a b

    2 7`

    I recommend specifying sensible names (not x/y) as much as possible.

    in reply to: 'host error setting up new kdb+ server #259

    John Dempster
    Keymaster

    Your license file from KX specifies what host is allowed to run KDB. The new machine has a different hostname.

    Copy the startup banner of the ‘host error kdb server process and send an email to KX with those details pasted in. They will then send you the required license file.

    in reply to: How much do Kdb+ developers make? #258

    John Dempster
    Keymaster

    It depends.. Despite what this post seems to suggest:
    http://magmasystems.blogspot.com/2007/12/get-rich-quick-with-kdb.html
    Kdb isn’t some golden ticket, your other qualifications and skills matter. What uni did you go to? What is your degree/masters in? Do you have any financial knowledge.

    Supposedly: http://www.itjobswatch.co.uk/jobs/uk/kdb.do
    Average salary £87,500
    Average salary % change year-on-year +6.06%
    90% offered a salary of more than £50,500
    10% offered a salary of more than £119,000

    Google the job sites
    http://www.indeed.co.uk/Kdb-jobs

    Contact some recruiters on linkedin. Ask Friends.

    in reply to: How to list all tables that exist on kdb server? #256

    John Dempster
    Keymaster

    To show variables that exist on the server there are a number of system or slash commands:

    q)t:([] a:1 2)
    q)s:([] b:3 4)
    q)v:1
    q)f:{x}
    q)vieww::select from t where i<1

    System or slash a to show tables.
    q)system “a”
    `s`t
    q)\a
    `s`t
    q)tables[]
    `s`t

    b is views, v is variables, f is functions
    q)\b
    ,`vieww
    q)\v
    `b`s`t`v
    q)\f
    `cls`f`regr

    Or key shows all objects that exist in a namespace:

    q)key `.
    `cls`regr`b`t`s`v`f`vieww

    • This reply was modified 11 years, 7 months ago by John Dempster.
    in reply to: vim kdb keyword syntax highlight #255

    John Dempster
    Keymaster

    Vim Syntax highlighting is possible. See details here for setting up kdb:
    http://www.timestored.com/kdb-guides/developer-environment

    in reply to: run q script in kdb console #254

    John Dempster
    Keymaster

    Either use \l or system l to load q script files.

    C:\>echo “show `helloWorld” >> hi.q

    C:\>q
    KDB+ 2.8 2012.02.05 Copyright (C) 1993-2012 Kx Systems
    w64/ 8()core 8169MB admin box 192.168.0.2 EXPIRE 2013.12.31

    q)\l hi.q
    “show `helloWorld”
    q)system “l hi.q”
    “show `helloWorld”

    Multi-line commands are tricky, I would instead use the qStudio KDB GUI that allows highlighting the text you want and executing it.

    in reply to: for loop evil, but wanted #144

    John Dempster
    Keymaster

    the q language does not have a for loop. Other control statements are available. e.g.


    q)i:0; while[i<3; show i; i:i+1]; show `end
    0
    1
    2
    `end
    q)i
    3

    q)do[3; show i; i:i+1]; show `end
    6
    7
    8
    `end

    if, else are also possible.

Viewing 11 posts - 16 through 26 (of 26 total)