Skip to main content
VeloDB Cloud 26.x is based on Apache Doris 4.x. See Version Mapping.

Alias Function

An alias function registers a reusable SQL expression under a new name. Use it to adapt function names when migrating queries from another database or to replace repeated expressions with a concise function call. Calling the alias evaluates its underlying expression.

Alias functions use SQL expressions and do not require a Java JAR or Python runtime. Creating an alias function requires a warehouse SQL user with the ADMIN privilege. See CREATE FUNCTION.

Scope​

ScopeRegistration rangeHow to call
DatabaseThe current database, or the database named in the function nameUse the function name in that database. From another database, qualify it as database_name.function_name.
GLOBALThe warehouseUse the function name from any database in the same warehouse.

Create a database-scoped alias with CREATE ALIAS FUNCTION. Add GLOBAL to create a warehouse-wide alias. Database-scoped function lookup requires SELECT on the database.

Use cases​

Adapt function names during migration​

Queries from another database may use a different name for an expression that VeloDB Cloud can evaluate. Define an alias with the original name to reuse those queries. Check argument types and expression behavior before relying on the alias for compatibility.

Simplify repeated expressions​

An alias can replace a repeated expression with a named function call. This makes queries easier to read and lets you maintain the expression in one place.

Expression requirements​

In Core 26.1.3, the expression must have a function call or a supported CAST at its root. For a scalar CAST root, supported target types are DECIMAL, CHAR, and VARCHAR. A top-level arithmetic operator or CASE expression is not supported. The examples below use function calls.

Example 1: Wrap an arithmetic expression in a function​

Register an alias that returns an absolute value

Select a database, then register the alias:

CREATE ALIAS FUNCTION func(INT, INT)
WITH PARAMETER(foo, bar) AS abs(foo + bar);

The root expression is the ABS function, so the arithmetic expression inside it is valid.

Example 2: Compose date functions​

Register an alias that subtracts days and truncates a timestamp
CREATE ALIAS FUNCTION func(DATETIMEV2(3), INT)
WITH PARAMETER(foo, bar) AS date_trunc(days_sub(foo, bar), 'day');

The root expression is DATE_TRUNC, with DAYS_SUB nested inside it. This signature differs from the first example and can use the same function name.

Example 3: Recognize an unsupported root expression​

Understand why a top-level arithmetic operator is rejected

The following statement is invalid because its root expression is an addition operator:

CREATE ALIAS FUNCTION func(INT, INT)
WITH PARAMETER(foo, bar) AS foo + bar;

Wrap the expression in a supported function, as shown in the first example.

Parameter requirements​

  • The declared argument types and named parameters must have the same count.
  • Parameter names must be unique. Each named parameter must be referenced by the expression or a supported CAST type definition.
  • A function without arguments can use an empty argument list and WITH PARAMETER(). For example, Core 26.1.3 supports CREATE ALIAS FUNCTION current_time_alias() WITH PARAMETER() AS now().
  • Use fixed argument signatures for the examples in this guide. To accept a collection of values, use an ARRAY argument.

See also​