rename column in kdb - Kdb+ / qStudio

Home Forums Kdb+ / qStudio rename column in kdb

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Ryan Hamilton 5 years, 8 months ago.

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

    Matt Bell

    Hi,

    How can I rename columns or reorder columns in kdb database?

    I have a table with columns alpha, net, gross and want to rename the columns?

    #23775

    Hi Matt,

    To rename columns in kdb you can use xcol.
    xcol takes two arguments, it’s first is a symbol list used for the new names of the columns, starting from the leftmost column. The second argument is the table itself. The list of new names can be fewer than the columns, in that case the rightmost columns keep their original name.

    For example:

    q)t:([] aa:1 2; bb:3 4; cc:5 6)
    q)t
    aa bb cc
    ——–
    1 3 5
    2 4 6

    q)`col1`col2 xcol t
    col1 col2 cc
    ————
    1 3 5
    2 4 6

    For reordering columns you can use xcols.

    xcols takes two arguments.
    1. A symbol list of existing column names, that will be ‘pulled’ to the left hand side of the table.
    2. The table name itself.

    For example:

    q)`cc`aa xcols t
    cc aa bb
    ——–
    5 1 3
    6 2 4

    • This reply was modified 5 years, 8 months ago by  Ryan Hamilton.
    • This reply was modified 5 years, 8 months ago by  Ryan Hamilton.
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘rename column in kdb’ is closed to new replies.