pyspark.sql.Catalog.truncateTable#

Catalog.truncateTable(tableName)[source]#

Truncates a table (removes all data from the table; not supported for views).

New in version 4.2.0.

Parameters
tableNamestr

Name of the table to truncate. May be qualified with catalog and database (namespace).

Examples

>>> _ = spark.sql("DROP TABLE IF EXISTS tbl_tr_doc")
>>> _ = spark.sql("CREATE TABLE tbl_tr_doc (id INT) USING csv")
>>> _ = spark.sql("INSERT INTO tbl_tr_doc VALUES (1), (2)")
>>> spark.table("tbl_tr_doc").count()
2
>>> spark.catalog.truncateTable("tbl_tr_doc")
>>> spark.table("tbl_tr_doc").count()
0
>>> _ = spark.sql("DROP TABLE tbl_tr_doc")