Matt BellGuest
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?
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 10 years, 10 months ago by Ryan Hamilton.
-
This reply was modified 10 years, 10 months ago by Ryan Hamilton.