Reputation: 8713
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
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
To clear the contents for one date simply delete that folder and then \l
.
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
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