Does kdb+ support views? Materialised views? - Kdb+ / qStudio

Home Forums Kdb+ / qStudio Does kdb+ support views? Materialised views?

Tagged: 

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

    Matt
    Guest

    Hi,

    I am more familiar with other standard database systems and I can’t seem to find any mention of using views in kdb+.

    Does kdb+ have views?

    #538

    kdb+ does support a form of views. You use double colon :: to assign a view of a table to a variable. The result then becomes cached in that variable and is only updated as necessary when the underlying table changes.

    e.g.

    `q)t:([] a:til 1000000)
    q)select from t where a in 1 1000 2000
    a
    —-
    1
    1000
    2000`

    Create the view

    `
    q)myView::select from t where a in 1 1000 2000
    q)myView
    a
    —-
    1
    1000
    2000`

    Notice time to query cached view is 0

    `
    q)\t do[100; select from t where a in 1 1000 2000]
    377
    q)\t do[100; myView]
    0`

    insert new value, next query costs a little

     

    q)`t insert ([] a:999999 2000)
    1000000 1000001
    q)\t do[100; myView]
    5

    updated data shown

    `
    q)myView
    a
    —-
    1
    1000
    2000
    2000`

    system “b” or \b will display the views that exist within your kdb+ process.

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

The topic ‘Does kdb+ support views? Materialised views?’ is closed to new replies.