Auto increment

Hi, still learning Kdb wondering is there a way to create a unique auto increment unique id everytime a record is inserted into a table?

Also after inserting values to a table how do you ensure that the values are saved to disk in case the q process crashes and you lose your data only way I know is to run the save ':mytable

Any insights appreciated,

Thanks.
Brian

there is no autoincrement, unless you keep your own sequence number, e.g.
seq:0;

upd:{[t;d] 

 t insert update seqNum:seq from d;

 seq+:1; 

 };

notice also that each row in a table has an associated index value accessible via the internal column “i”, e.g.

select sym,i from trade 

wrt saving to disk, in a real world setup you probably want to have a look at kdb+ tick http://code.kx.com/wiki/Startingkdbplus/tick

Thank you.

Hi Brian

If your database is big and needs to be partitioned, then as Walter says you probably do want to start looking at kdb+ tick.

However, if it fits in memory then you could use logging mode for persistence: http://code.kx.com/wiki/Cookbook/Logging

Hope this helps

Natalie

if you don’t need a sequence, there’s also guids, the random generation of which use things like time, process id, port number to generate uniques.

http://code.kx.com/wiki/Reference/Datatypes

q)-1?0Ng

,81b10e63-8ee6-d3e5-2011-6b2b53598880