Listing table names

Learn how to list table names in Databricks.

Written by Adam Pavlacka

Last published at: May 16th, 2022

Problem

To fetch all the table names from metastore you can use either spark.catalog.listTables() or %sql show tables. If you observe the duration to fetch the details you can see spark.catalog.listTables() usually takes longer than %sql show tables.

Cause

spark.catalog.listTables() tries to fetch every table’s metadata first and then show the requested table names. This process is slow when dealing with complex schemas and larger numbers of tables.

Solution

To get only the table names, use %sql show tables which internally invokes SessionCatalog.listTables which fetches only the table names.