0

A query result looks good if I break keyed table apart into key-value pair and combine them together: key!value. But a straight select from it gives an error. I constructed that keyed table in a slightly weird manner:

q)show t:([n:1 2] m:(`a`b!3 4;`a`b!5 6));
n| m
-| --------
1| `a`b!3 4
2| `a`b!5 6
q)t[;`m]
n| a b
-| ---
1| 3 4
2| 5 6
q)select from (key t[;`m])!value t[;`m]
n| a b
-| ---
1| 3 4
2| 5 6
q)select from t[;`m]
'type
  [0]  select from t[;`m]
       ^

Where does this 'type error come from?

egor7
  • 4,678
  • 7
  • 31
  • 55

1 Answers1

3

Doing an exact match on what we expect t[;`m] to be shows that something is up. If we deconstruct and reconstruct we get them being equal.

q)([n:1 2]a:3 5;b:4 6)~t[;`m]
0b
q)([n:1 2]a:3 5;b:4 6)~{key[x]!value x}t[;`m]
1b

We can get clues from the internal byte representation using -8!, which unfortunately is not well documented. It seems that the values are being represented as a general list (type 0h => 0x00) of dictionaries instead of a table (type 98h => 0x62).

q)-8!`a`b!3 4
0x0100000029000000630b00020000006100620007000200000003000000000000000400000000000000
q)-8!t[;`m]
0x0100000078000000636200630b00010000006e0000000100000007000200000001000000000000000200000000000000000002000000630b00020000006100620007000200000003000000000000000400000000000000630b00020000006100620007000200000005000000000000000600000000000000
q)-8!([n:1 2]a:3 5;b:4 6)
0x010000006f000000636200630b00010000006e00000001000000070002000000010000000000000002000000000000006200630b0002000000610062000000020000000700020000000300000000000000050000000000000007000200000004000000000000000600000000000000
Mark Kelly
  • 1,780
  • 7
  • 16