KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ How to convert below functional select query to a QSQL format.

  • How to convert below functional select query to a QSQL format.

    Posted by Laura on February 2, 2024 at 12:00 am

    Hi All,
    I am new to kdb and wanted to prepare a report containing information of how many rows are seen in variable rdb tables. For this I see we can get that via below functional query that provide us dictionary with table name and count

    (tables[] ! { count value (? ; x ; () ; 0b ; () ) } each tables[]

    Above gives me the expected output, but I wanted to perform this via qsql for my understanding. But this gives me the error.

    tables[] ! ( { count value ( select from x ) } each tables [] )

    I tried to use the implicit argument x and passed it to function which then count the number of rows inside the lambda function and then tried passing it parameter  each tables []  which results into an error. How can I debug this error with some meaningful error thrown and what would be right way to do it ?

    Thanks in advance.

    Laura replied 8 months, 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • rocuinneagain

    Member
    February 2, 2024 at 12:00 am

    The first example line you show is creating parse trees and then evaluating them with value

    https://code.kx.com/q/basics/parsetrees/

    You then replace the parse tree with a qsql statement which evaluates, this means you no longer need value:

    tables[]!{count select from x} each tables[]

    The debugger uses ^ to show you exactly where the error is thrown

    // ^ tells us the error happened when value was run

    q)tables[] ! ( { count value ( select from x ) } each tables [] ) 'type [2] { count value ( select from x ) } ^ 
    
    q))select from x // select from x returns a table a - 1 2 3 q))value select from x //Running value on a table is not a valid command 'type [4] value select from x ^ 
    
    q))count select from x //We should run count directly on the returned table 3

    See: https://code.kx.com/q/basics/debug/

Log in to reply.