Robert Kubrick
Robert Kubrick

Reputation: 8713

How to delete a kdb partitioned table contents?

I wrote a q script to create a partitioned table and insert rows from a large kdb file I previously saved. The script only saves data for a specific date that I pass in from the command line.

How can I clear the contents of the partitioned table at the begin of the script? Or more in general, how can I insure the table contents are not duplicated if I run the script more than once?

Upvotes: 1

Views: 3248

Answers (2)

John at TimeStored
John at TimeStored

Reputation: 1315

Going to assume your partitioned by date, so directory structure:

2012.04.03
          /trade
2012.04.04
          /trade
2012.04.05
          /trade
                /ticker
                /price
                /size
  1. To clear the contents for one date simply delete that folder and then \l.

  2. To prevent duplicating check if any data first exists for that date:

    select count i from trade where date=2012.04.06

If one dates data may come from different files that makes it trickier. You may want to add a sourceFile column and or as a separate table to keep track of which files were loaded.

Upvotes: 3

Pratyush
Pratyush

Reputation: 71

You can also incorporate the deletion process in a q function. Say the location you write is in the format:

/hdb/date/tablename/colname

q) db1:"/hdb/date";    / you can pass this as a argument in a function

q) deletedb:{[dbname] systemcmd: "rm -rfv ",dbdelete; system systemcmd}

q) deletedb db1

Upvotes: 1

Related Questions