Insert and Upsert Behavior in KDB

I have the following table:

q) t:([s:`symbol$()] id:();id2:`int$()) 

where 's' is the primary key, and 'id' col is of a common type. I am trying to understand the following behavior when inserting a list (row in this example) into the "id" column:

a) Upsert works, but Insert failed

  q) `t insert (`a;"gg";4) // 'type q) `t upsert (`a;"gg";4) // works 

b) The insert requires that the primary key also be credited:

  q)`t insert (`a;enlist "gg";4) // 'length q)`t insert (enlist `a;enlist "gg";4) // works 

What is going on behind the scenes?

+8
database insert primary-key kdb
source share
1 answer

I believe the problem with "gg" is the list, so the insertion is confused whether you are trying to insert one entry or several. It:

 `t insert (`a;"g";4) 

works just fine. Unfortunately, I do not know another workaround, but I give insert list of records of length one:

 `t insert (enlist `c;enlist "gg";enlist 4) 

I'm not sure what happened with upsert , but this may have something to do with its implementation through a change:. .[;();,;]

+1
source share

All Articles