Skip to main content

listColumns

Returns a list of columns for the given table/view in the specified database.

Syntax

listColumns(tableName: str, dbName: str = None)

Parameters

Parameter

Type

Description

tableName

str

Name of the table to list columns. Can be qualified with catalog name when dbName is None.

dbName

str, optional

Name of the database to find the table to list columns.

Returns

list of Column

Notes

The order of arguments here is different from that of its JVM counterpart because Python does not support method overloading.

If no database is specified, the current database and catalog are used. This API includes all temporary views.

Examples

Python
_ = spark.sql("DROP TABLE IF EXISTS tbl1")
_ = spark.sql("CREATE TABLE tblA (name STRING, age INT) USING parquet")
spark.catalog.listColumns("tblA")
# [Column(name='name', description=None, dataType='string', nullable=True, ...
_ = spark.sql("DROP TABLE tblA")