String column comparisons in kdb+ - Kdb+ / qStudio

Home Forums Kdb+ / qStudio String column comparisons in kdb+

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #620

    Oskar Morgenstern
    Guest

    Hi,

    How do I compare strings for equality in kdb+?
    I have tried the following:

    `q)t:([] row:1 2 3 4 5; company:(“Ford”;”Nissan”;”Skoda”;”GM”;”Rover”))
    q)t
    row company
    ————
    1 “Ford”
    2 “Nissan”
    3 “Skoda”
    4 “GM”
    5 “Rover”

    q)select from t where company=”Ford”
    ‘length
    =
    (“Ford”;”Nissan”;”Skoda”;”GM”;”Rover”)
    “Ford”
    q)select from t where company~”Ford”
    row company
    ———–
    `

    Strangely in seems to work as expected but this isn’t an ideal solution.
    `
    q)select from t where company in (“Ford”;”Ford”)
    row company
    ———–
    1 “Ford”`

    Why do I get a length error comparing the strings using equals?

    Thanks.

    #645

    Scott F
    Guest

    You can use like to compare strings:

    q)select from t where company like “Ford”
    row company
    ———–
    1   “Ford”

    Regards

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.