Skip to content

cols, xcol, xcols

Table columns


Column names of a table

cols x    cols[x]

Where x is a

  • table
  • the name of a table as a symbol atom
  • a filesymbol for a splayed table

returns as a symbol vector its column names.

q)\l trade.q
q)cols trade            /value
q)cols`trade            /reference


Rename table columns

x xcol y    xcol[x;y]

Where y is a table, passed by value, and x is

  • a symbol vector of length no greater than count cols y returns y with its first count x columns renamed
  • a dictionary (since V3.6 2018.08.24) formed from two symbol vectors, of which the keys are all the names of columns of y, returns y with columns renamed according to the dictionary
q)\l trade.q
q)cols trade
q)`Time`Symbol xcol trade                   / rename first two columns
Time         Symbol price size
09:30:00.000 a      10.75 100
q)trade:`Time`Symbol`Price`Size xcol trade  / rename all and assign
q)cols trade
q)cols(`a`c!`A`C)xcol([]a:();b:();c:())     / selected columns
A b C

Q for Mortals §9.8.1 xcol


Reorder table columns

x xcols y    xcols[x;y]


  • y is a simple table, passed by value
  • x is a symbol vector of some or all of y’s column names

returns y with x as its first column/s.

q)\l trade.q
q)cols trade
q)trade:xcols[reverse cols trade;trade] / reverse cols and reassign trade
q)cols trade
q)trade:`sym xcols trade                / move sym to the front
q)cols trade

Q for Mortals §9.8.2 xcols

.Q: .Q.V (table to dictionary)
Basics: Dictionaries & tables, Metadata