Share via


substr

Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.

For the corresponding Databricks SQL function, see substr function.

Syntax

from pyspark.databricks.sql import functions as dbf

dbf.substr(str=<str>, pos=<pos>, len=<len>)

Parameters

Parameter Type Description
str pyspark.sql.Column or str A column of string.
pos pyspark.sql.Column or str A column of string, the substring of str that starts at pos.
len pyspark.sql.Column or str, optional A column of string, the substring of str is of length len.

Returns

pyspark.sql.Column: substring of given value.

Examples

from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([("Spark SQL", 5, 1,)], ["a", "b", "c"])
df.select("*", dbf.substr("a", "b", "c")).show()
df.select("*", dbf.substr(df.a, df.b)).show()