truncate

Syntax

truncate(dbUrl, tableName)

Details

Remove all rows from a DFS table but keep its schema. Command truncate is faster than the delete statement and the dropPartition function.

It is suggested to call function dropTable if you want to delete the schema of the table.

Difference from Python’s scipy.stats.truncate: scipy.stats.truncate is a truncated random variable distribution object. DolphinDB’s truncate is a database management function that clears the data of a DFS table specified by tableName in the database specified by dbUrl while preserving the table schema.

Parameters

dbUrl is a string indicating the DFS path of a database.

tableName is a string indicating the table name.

Returns

None.

Example

n=1000000
ID=rand(150, n)
dates=2017.08.07..2017.08.11
date=rand(dates, n)
x=rand(10.0, n)
t=table(ID, date, x)
dbDate = database(, VALUE, 2017.08.07..2017.08.11)
dbID = database(, RANGE, 0 50 100 150)

dbName="dfs://compoDB"
if(existsDatabase(dbName)){

      dropDatabase(dbName)
}
db = database(dbName, COMPO, [dbDate, dbID])
pt = db.createPartitionedTable(t, `pt, `date`ID)
pt.append!(t);

truncate(dbName, `pt)