How to use the type “c”and “C” in kdb

  • A+

When i used meta tableName to check type .get below result :

c                t        f      a `description     "C" 

And now I want to know the diff between type "c" and "C". and how to cast the type "c" into "C".

From the following explanation I can get that when there is a "c" type in a table, I can convert it to "C" type. My new question is as follows: table1:

([ID:`1`2`3]Name:`A`B`C;Client:`P`Q`S;Species:`setosa`setosa`setosa   ;Length:2 34 6) 

showing as below:

ID Name  Client    Species  Length  1    A     B        setosa    2  2    B     Q        setosa    34  3    C     S        setosa    6 

And I want to write a simple api for table1:

.get.table1:{[Params]   if[Params~();Params:()!()];    select ID:ID,NAME:Name,CLIENT:Client,SPECIES:Species,LENGTH:Length,DESCRIP:count[i]#enlist "" from table1     } 


ID NAME  CLIENT    SPECIES  LENGTH  DESCRIP  1    A     B        setosa    2       ""  2    B     Q        setosa    34      ""  3    C     S        setosa    6       "" 

meta table1:

c             t   f   a ID            s NAME          s CLIENT        s LENGTH        j DESCRIP       C 

Now, I want to change the writing style of an api to get the same result as the api above. What should I do?(How to describe the DESCRIP line)

.get.table1:{[Params]    if[Params~();Params:()!()];    defaultCols:`ID`NAME`CLIENT`SPECIES`LENGTH`DESCRIP!(`ID;`Name;`Client;`Species`;`Length;**DESCRIP**)    if[`extraCols in key Params;    extraCols:$[-11h=type Params`extraCols;enlist[Params`extraCols]!enlist  Params`extraCols;(Params`extraCols)!Params`extraCols]; defaultCols:defaultCols,extraCols]; ?[select from table1;();0b;defaultCols]  } 


Type "c" means that each element is in the column is atomic, whereas type "C" means that each element in the column is a list of that type. To convert from "c" to "C" you can enlist each character to make it into a list.

q) meta ([] c:"123") c| t f a -| ----- c| c  q) meta ([] c:enlist each "123") c| t f a -| ----- c| C 

Querying a string column will be inefficient. If your column has a small set of distinct values that are repeated often, casting the column to a symbol column will be more efficient


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: