CREATE FUNCTION
Translation reference for the BigQuery User Defined Functions
BigQuery supports UDFs written in either SQL or Javascript
Syntax to create a SQL UDF
CREATE [ OR REPLACE ] [ TEMPORARY | TEMP ] FUNCTION [ IF NOT EXISTS ]
[[project_name.]dataset_name.]function_name
([named_parameter[, ...]])
([named_parameter[, ...]])
[RETURNS data_type]
AS (sql_expression)
[OPTIONS (function_option_list)]
named_parameter:
param_name param_typeCode Samples
-- Sample 1 - IF NOT EXISTS and NO RETURNS CLAUSE
CREATE FUNCTION IF NOT EXISTS test.basic (x string)
AS (x);
-- Sample 2 - TEMPORARY
CREATE TEMPORARY FUNCTION temporary (param1 integer, param2 integer)
RETURNS INTEGER
AS (param1 * param2);
-- Sample 3 - OR REPLACE
CREATE OR REPLACE FUNCTION test.orReplace ()
RETURNS INTEGER
AS (select colX from tableY);
-- Sample 4 - OPTIONS
CREATE FUNCTION funcOptionsNoReturns (param1 integer)
AS (x * y)
OPTIONS(
description="UDF with all supported options",
library=["gs://my-bucket/lib1.js", "gs://my-bucket/lib2.js"],
endpoint="https://www.snowflake.com/foo",
user_defined_context=[("key1","value1"),("key2", "value2")],
max_batching_rows=1000
);
Syntax to create Javascript UDF
Code Samples
Syntax to create a remote function
The transformation for remote function is currently not being transformed to Snowflake.
Related EWIs
MSC-BQ0003: The Create Function Options clause is not supported by Snowflake.
Last updated
Was this helpful?