User-Defined Function (UDF)

From Ilianko

← Back to DP-420 Terminology Reference

Category: Server-Side Programming

Summary: Read-only JavaScript function extending SQL queries with custom computations.

Overview

A user-defined function (UDF) is server-side JavaScript logic in Azure Cosmos DB for NoSQL that extends the SQL query language with custom scalar computations (e.g., custom string formatting or calculations), callable from within a SQL query. Unlike stored procedures and triggers, UDFs are read-only and cannot modify data.

[Image: udf.png (User-Defined Function)]

More Info & Links

DP-420 Style Practice Questions

Q1. What is the primary purpose of a user-defined function (UDF) in Azure Cosmos DB for NoSQL?

  • A. Extending SQL queries with custom, read-only scalar computations
  • B. Performing multi-item transactional writes
  • C. Automatically triggering on every item creation
  • D. Managing container-level throughput

Q2. Can a UDF modify data in Azure Cosmos DB?

  • A. No, UDFs are read-only and cannot modify data
  • B. Yes, UDFs can perform inserts, updates, and deletes
  • C. Only if invoked from a stored procedure
  • D. Only for items within the same partition

Answer Key

Answers are listed at the very end so you can attempt the questions first.

  • Q1 (User-Defined Function (UDF)): A. Extending SQL queries with custom, read-only scalar computations — UDFs add custom computational logic callable from SQL queries, but unlike stored procedures/triggers, they cannot write data.
  • Q2 (User-Defined Function (UDF)): A. No, UDFs are read-only and cannot modify data — UDFs are restricted to read-only scalar computation and cannot write or modify data.

DP-420: Designing and Implementing Cloud-Native Applications Using Microsoft Azure Cosmos DB — term detail page