---
title: overlay
description: "overlay function in PySpark: Overlay the specified portion of src with replace, starting from byte position pos of src and proceeding for len bytes."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/overlay
---

# overlay

Overlay the specified portion of `src` with `replace`, starting from byte position `pos` of `src` and proceeding for `len` bytes.

For the corresponding Databricks SQL function, see [`overlay` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/overlay.md).

## Syntax

```python
from pyspark.sql import functions as dbf

dbf.overlay(src=<src>, replace=<replace>, pos=<pos>, len=<len>)
```

## Parameters

| Parameter | Type                                             | Description                                                                                                                   |
| --------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
| `src`     | `pyspark.sql.Column` or `str`                    | the string that will be replaced                                                                                              |
| `replace` | `pyspark.sql.Column` or `str`                    | the substitution string                                                                                                       |
| `pos`     | `pyspark.sql.Column` or `str` or `int`           | the starting position in src                                                                                                  |
| `len`     | `pyspark.sql.Column` or `str` or `int, optional` | the number of bytes to replace in src string by 'replace' defaults to -1, which represents the length of the 'replace' string |

## Returns

`pyspark.sql.Column`: string with replaced values.

## Examples

```python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([("SPARK_SQL", "CORE")], ("x", "y"))
df.select("*", dbf.overlay("x", df.y, 7)).show()
df.select("*", dbf.overlay("x", df.y, 7, 0)).show()
df.select("*", dbf.overlay("x", "y", 7, 2)).show()
```
