Contango
Contango

Reputation: 80262

KDB: Convert a dictionary of tables into a table?

As per question, I have a dictionary of tables. How do I join the values into a single table?

Upvotes: 1

Views: 568

Answers (3)

nikeros
nikeros

Reputation: 3379

It is easy to see what raze does:

parse "raze d"
,/
`d

As a matter of fact, personally in the past I have used the following command to achieve the same output:

(),/ d

Upvotes: 1

terrylynch
terrylynch

Reputation: 13572

raze works if the schemas of the tables all conform (aka all columns are the same and in the same order). If they don't conform, a more general option is to union join over:

/tables conform
q)raze `a`b!(([]col1:`x`y;col2:1 2);([]col1:`z`w;col2:3 4))
col1 col2
---------
x    1
y    2
z    3
w    4

/column order different
q)raze `a`b!(([]col1:`x`y;col2:1 2);([]col2:3 4;col1:`z`w))
`col1`col2!(`x;1)
`col1`col2!(`y;2)
`col2`col1!(3;`z)
`col2`col1!(4;`w)

/non-matching columns
q)raze `a`b!(([]col1:`x`y;col2:1 2);([]col2:3 4;col1:`z`w;col3:01b))
`col1`col2!(`x;1)
`col1`col2!(`y;2)
`col2`col1`col3!(3;`z;0b)
`col2`col1`col3!(4;`w;1b)

/uj handles any non-conformity
q)(uj/)`a`b!(([]col1:`x`y;col2:1 2);([]col2:3 4;col1:`z`w;col3:01b))
col1 col2 col3
--------------
x    1    0
y    2    0
z    3    0
w    4    1

Upvotes: 2

Contango
Contango

Reputation: 80262

Use:

raze x

Raze is defined as:

Return the items of x joined, collapsing one level of nesting.

The table will not include the key, but if the key is also in each table then no information is lost.

Upvotes: 1

Related Questions