Search code examples
kdb

How do I select from a table rows with no nulls?


In KDB, I have a query of the form:

select from t where not null a, not null b

Is it possible to select rows that contain no nulls, rather than specifying a and b?


Solution

  • For a simple t then something like the below may work:

    q)t:([]a:1 2 3 4;b:1 2 0N 4;c:1 2 3 0N)
    q)t
    a b c
    -----
    1 1 1
    2 2 2
    3   3
    4 4
    q)t where not any flip null t
    a b c
    -----
    1 1 1
    2 2 2
    

    This will check all columns for nulls and only return the indices for those columns with no nulls. For tables with columns containing strings, or lists of lists, this will fail and you will need more in-depth logic.