# SCALAR UDF with ALTER TABLE Clause

**URL:** <https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254>\
**Category:** Uncategorized\
**Created:** [September 3, 2024, 4:37pm UTC](https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254 "2024-09-03T16:37:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnie](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arnie](https://community.dremio.com/u/Arnie)\
**Post date:** [September 3, 2024, 4:37pm UTC](https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254/1 "2024-09-03T16:37:47Z")

</div>

Hello  
Current documentation points that DML statements cannot be used with RETURN.  
I am testing something following lines and get ‘Encountered “TABLE” at line 3, column 14.’ message. Do you confirm my syntax is not supported ? and do you have any plan to support DML instruction in UDF ?

CREATE OR REPLACE FUNCTION refresh\_table(tgt VARCHAR)  
RETURNS TABLE (ok VARCHAR, summary VARCHAR)  
RETURN ALTER TABLE tgt REFRESH METADATA FORCE UPDATE

---

<div class="post-metadata">

**Author:** ![Benny\_Chow](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/benny_chow/32/5527_2.png) [@Benny\_Chow](https://community.dremio.com/u/Benny_Chow)\
**Post date:** [September 5, 2024, 10:42pm UTC](https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254/2 "2024-09-05T22:42:34Z")

</div>

Hi Arnie, can you provide link to this doc?

---

<div class="post-metadata">

**Author:** ![Arnie](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arnie](https://community.dremio.com/u/Arnie)\
**Post date:** [September 9, 2024, 7:20am UTC](https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254/3 "2024-09-09T07:20:13Z")

</div>

Current documentation is :

> **[User-Defined Functions | Dremio Documentation](https://docs.dremio.com/current/reference/sql/commands/functions/)**
>
> A user-defined function (UDF) is a callable routine that accepts input parameters, executes the function body, and returns a single scalar value. UDFs are used with Dremio in the context of assigning row-level filtering and column-masking policies.

In the documentation RETURN is described with its limits.

RETURN { expression | query } String

The body of the function. For a scalar function, it can either be a query or an expression. For a tabular function, it may only be a query. The expression may not contain the following:

- DML statements such as `INSERT`, `UPDATE`, or `DELETE`.
- DDL statements such as `CREATE` and `DROP`.

---

<div class="post-metadata">

**Author:** ![Arnie](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arnie](https://community.dremio.com/u/Arnie)\
**Post date:** [February 24, 2026, 6:58pm UTC](https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254/4 "2026-02-24T18:58:47Z")

</div>

Any update on this thread ?

---

<div class="post-metadata">

**Author:** ![piledalu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/piledalu/32/6777_2.png) [@piledalu](https://community.dremio.com/u/piledalu)\
**Post date:** [November 1, 2026, 6:42pm UTC](https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254/5 "2026-11-01T18:42:37Z")

</div>

ALTER TABLE`is DDL, so it isn’t valid in a UDF’s`RETURN` body; tabular UDFs must return a query. Run the refresh as a separate SQL statement. I don’t know of a supported way for a UDF to perform that metadata change.

---

<div class="post-metadata">

**Author:** ![piledalu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/piledalu/32/6777_2.png) [@piledalu](https://community.dremio.com/u/piledalu)\
**Post date:** [November 19, 2026, 10:12am UTC](https://community.dremio.com/t/scalar-udf-with-alter-table-clause/12254/6 "2026-11-19T10:12:25Z")

</div>

ALTER TABLE`is DDL, so it isn’t valid in a UDF’s`RETURN` body; tabular UDFs must return a query. Run the refresh as a separate SQL statement. I don’t know of a supported way for a UDF to perform that metadata change.
