Showing results for 
Search instead for 
Did you mean: 

clear contents of a partitioned table

New Contributor III
Hi all,

Anyone know how do I clear the contents of a partitioned table segmented by date for all dates?

New Contributor
Do you want to (a) just empty out the contents for all dates but keep the table ? or (b) completely remove the table from the database?

If (b) -- you just need to find all directories with the table name under each partition and delete them
if (a) -- create a zero row in-memory copy of the table, and write to all partitions

for (a) code would look something like (note, this is untested code) 

// assumes table name is 'someTable' - and root of hdb is set in var 'dbRoot'
q) (` sv'.Q.par[dbRoot;;`someTable]'[date],\:`) set\: .Q.en[dbRoot] delete date from select from someTable where date=max date, i = -1

The above code will (working right to left)
1) select 'someTable' from disk, row -1 (creates a 0 row table)
2) deletes date column
3) enumerates symbol columns (although this is actually unnecessary in the above case, as all symbol columns will be enumerated as we've just selected them from disk)
4) constructs splay paths for the table for each of the dates  (see .Q.par) and saves the new empty table to each splay

Mohammad Noor

New Contributor
For general partitioned table management, may want to review dbmaint.q and the Dec 2012 Q for Gods whitepaper (see bottom of page 6) from First Derivatives.

Mohammad Noor