Skip to content

Latest commit

 

History

History
58 lines (38 loc) · 3.74 KB

create-functions.md

File metadata and controls

58 lines (38 loc) · 3.74 KB
title description ms.reviewer ms.author author ms.topic ms.custom ms.date ms.search.form
Create stored functions in Real-Time Intelligence
Learn how to use the `.create-or-alter function` command to create stored functions in Real-Time Intelligence.
tzgitlin
yaschust
YaelSchuster
how-to
build-2023
ignite-2023
04/21/2024
product-kusto

Create stored functions

Functions are reusable queries or query parts. Real-Time Intelligence supports two kinds of functions:

  • Built-in functions, which are hard-coded functions that can't be modified by users.

  • User-defined functions, which are divided into two types:

    • Stored functions: are user-defined functions that are stored and managed database schema entities (such as tables). For more information on how to create and manage stored functions, see Stored functions management overview.
    • Query-defined functions: are user-defined functions that are defined and used within the scope of a single query. The definition of such functions is done through a let statement. For more information on how to create query-defined functions, see Create a user defined function.

In this article, you learn how to create or alter an existing stored function using the .create-or-alter function.

For more information on the .create-or-alter function command, see .create-or-alter function

Prerequisites

Functions

This feature allows you to create or alter an existing function using the .create-or-alter function command, which stores it in the database metadata. If the function with the provided functionName doesn't exist in the database metadata, the command creates a new function. Otherwise, the named function is changed.

  1. Browse to your KQL database, and select New > Function. The .create-or-alter command is automatically populated in the Explore your data window.

    :::image type="content" source="media/create-functions/function-command.png" alt-text="Screenshot of a KQL database landing page showing the New option dropdown menu. The option titled Function is highlighted." lightbox="media/create-functions/function-command-extended.png":::

  2. Enter the function name and query parameters of your function instead of the placeholder text, and then select Run.

    :::image type="content" source="media/create-functions/create-function.png" alt-text="Screenshot of the Explore your data window showing the newly created function in Real-Time Intelligence." lightbox="media/create-functions/create-function.png":::

    Stored functions appear under Functions in the Explorer pane.

    :::image type="content" source="media/create-functions/functions-object-tree.png" alt-text="Screenshot of Explorer pane showing the list of stored user-defined functions.":::

  3. In the Explore your data window, run a query to check that you have successfully created or altered your function.

    :::image type="content" source="media/create-functions/function-example.png" alt-text="Screenshot of the Explore your data window showing query results of a stored function in Real-Time Intelligence." lightbox="media/create-functions/function-example.png":::

Related content