pyspark.sql.DataFrame.registerTempTable

DataFrame.registerTempTable(name: str) → None[source]

Registers this DataFrame as a temporary table using the given name.

The lifetime of this temporary table is tied to the SparkSession that was used to create this DataFrame.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Deprecated since version 2.0.0: Use DataFrame.createOrReplaceTempView() instead.

Parameters
namestr

Name of the temporary table to register.

Examples

>>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
>>> df.registerTempTable("people")
>>> df2 = spark.sql("SELECT * FROM people")
>>> sorted(df.collect()) == sorted(df2.collect())
True
>>> spark.catalog.dropTempView("people")
True