cancel
Showing results for 
Search instead for 
Did you mean: 

Keyed table with no value columns

borota
New Contributor
I want to define a "parent" table that has only a primary key as column. Trying this fails.

q) p:([k:`$()])
 'parse 

So based on what I am reading in Q for mortals I came up with this:

q) p:flip (enlist `k)!enlist `$()

Is there no table definition syntax to get the same result?

It looks like one can just use a list of symbols and enums in "child" tables to get a similar end result:

q) p:`k1`k1
q) c:([]c:`p$())

But I prefer to have a "parent" table still. For one it displays nicer in qStudio.
2 REPLIES 2

borota
New Contributor
Actually p:flip (enlist `k)!enlist `$() is not a keyed table, just a regular one column table. I guess there is no way to have a keyed table with a single column.

charlie
New Contributor II
New Contributor II
that's right. A keyed table is a dictionary where both the key and the value are flips.
e.g.
q)([]a:0 1;b:2 3)!([]c:4 5)
a b| c
---| -
0 2| 4
1 3| 5

As you can't define a dictionary with a key alone, you also can't define a keyed table with just the key flip.
It sounds like an enum is what you are looking for here.

If you like to view vectors as tables, just wrap them in ([]p) for display.