0

For a table t with a custom field c which is dictionary I could use select with limit expression, but simple select failes:

q)r1: `n`m`k!111b;
q)r2: `n`m`k!000b;
q)t: ([]a:1 2; b:10 20; c:(r1; r2));
q)t
a b  c
----------------
1 10 `n`m`k!111b
2 20 `n`m`k!000b
q)select[2] c[`n] from t
x
-
1
0
q)select c[`n] from t
'type
  [0]  select c[`n] from t
              ^

Is it a bug, or am I missing something?

Upd:

Why does select [2] c[`n] from t work here?

Mark Kelly
  • 1,780
  • 7
  • 16
egor7
  • 4,678
  • 7
  • 31
  • 55

1 Answers1

2

Since c is a list, it does not support key indexing which is why it has returned a type

You need to index into each element instead of trying to index the column.

q)select c[;`n] from t
x
-
1
0

A list of confirming dictionaries outside of this context is equivalent to a table, so you can index like you were

q)c:(r1;r2)
q)type c
98h
q)c[`n]
10b

I would say that the way complex columns are represented in memory makes this not possible. I suspect that any modification that creates a copy of a subset of the elements will allow column indexing as the copy will be formatted as a table.

One example here is serialising and deserialising the column (not recommended to do this). In the case of select[n] it is selecting a subset of 2 elements

q)type exec c from t
0h
q)type exec -9!-8!c from t
98h
q)exec (-9!-8!c)[`n] from t
10b
Mark Kelly
  • 1,780
  • 7
  • 16