Skip to main content

routines

Creates, updates, deletes, gets or lists a routines resource.

Overview

Nameroutines
TypeResource
Idgoogle.bigquery.routines

Fields

NameDatatypeDescription
descriptionstringOptional. The description of the routine, if defined.
argumentsarrayOptional.
creationTimestringOutput only. The time when this routine was created, in milliseconds since the epoch.
dataGovernanceTypestringOptional. If set to DATA_MASKING, the function is validated and made available as a masking function. For more information, see Create custom masking routines.
definitionBodystringRequired. The body of the routine. For functions, this is the expression in the AS clause. If language=SQL, it is the substring inside (but excluding) the parentheses. For example, for the function created with the following statement: CREATE FUNCTION JoinLines(x string, y string) as (concat(x, "\n", y)) The definition_body is concat(x, "\n", y) (\n is not replaced with linebreak). If language=JAVASCRIPT, it is the evaluated string in the AS clause. For example, for the function created with the following statement: CREATE FUNCTION f() RETURNS STRING LANGUAGE js AS 'return "\n";\n' The definition_body is return "\n";\n Note that both \n are replaced with linebreaks.
determinismLevelstringOptional. The determinism level of the JavaScript UDF, if defined.
etagstringOutput only. A hash of this resource.
importedLibrariesarrayOptional. If language = "JAVASCRIPT", this field stores the path of the imported JAVASCRIPT libraries.
languagestringOptional. Defaults to "SQL" if remote_function_options field is absent, not set otherwise.
lastModifiedTimestringOutput only. The time when this routine was last modified, in milliseconds since the epoch.
remoteFunctionOptionsobjectOptions for a remote user-defined function.
returnTableTypeobjectA table type
returnTypeobjectThe data type of a variable such as a function argument. Examples include: INT64: {"typeKind": "INT64"} ARRAY: { "typeKind": "ARRAY", "arrayElementType": {"typeKind": "STRING"} } STRUCT>: { "typeKind": "STRUCT", "structType": { "fields": [ { "name": "x", "type": {"typeKind": "STRING"} }, { "name": "y", "type": { "typeKind": "ARRAY", "arrayElementType": {"typeKind": "DATE"} } } ] } } RANGE: { "typeKind": "RANGE", "rangeElementType": {"typeKind": "DATE"} }
routineReferenceobjectId path of a routine.
routineTypestringRequired. The type of routine.
securityModestringOptional. The security mode of the routine, if defined. If not defined, the security mode is automatically determined from the routine's configuration.
sparkOptionsobjectOptions for a user-defined Spark routine.
strictModebooleanOptional. Use this option to catch many common errors. Error checking is not exhaustive, and successfully creating a procedure doesn't guarantee that the procedure will successfully execute at runtime. If strictMode is set to TRUE, the procedure body is further checked for errors such as non-existent tables or columns. The CREATE PROCEDURE statement fails if the body fails any of these checks. If strictMode is set to FALSE, the procedure body is checked only for syntax. For procedures that invoke themselves recursively, specify strictMode=FALSE to avoid non-existent procedure errors during validation. Default value is TRUE.

Methods

NameAccessible byRequired ParamsDescription
getSELECT+datasetId, +routineId, projectIdGets the specified routine resource by routine ID.
listSELECT+datasetId, projectIdLists all routines in the specified dataset. Requires the READER dataset role.
insertINSERT+datasetId, projectIdCreates a new routine in the dataset.
deleteDELETE+datasetId, +routineId, projectIdDeletes the routine specified by routineId from the dataset.
updateREPLACE+datasetId, +routineId, projectIdUpdates information in an existing routine. The update method replaces the entire Routine resource.

SELECT examples

Lists all routines in the specified dataset. Requires the READER dataset role.

SELECT
description,
arguments,
creationTime,
dataGovernanceType,
definitionBody,
determinismLevel,
etag,
importedLibraries,
language,
lastModifiedTime,
remoteFunctionOptions,
returnTableType,
returnType,
routineReference,
routineType,
securityMode,
sparkOptions,
strictMode
FROM google.bigquery.routines
WHERE +datasetId = '{{ +datasetId }}'
AND projectId = '{{ projectId }}';

INSERT example

Use the following StackQL query and manifest file to create a new routines resource.

/*+ create */
INSERT INTO google.bigquery.routines (
+datasetId,
projectId,
arguments,
dataGovernanceType,
definitionBody,
description,
determinismLevel,
importedLibraries,
language,
remoteFunctionOptions,
returnTableType,
returnType,
routineReference,
routineType,
securityMode,
sparkOptions,
strictMode
)
SELECT
'{{ +datasetId }}',
'{{ projectId }}',
'{{ arguments }}',
'{{ dataGovernanceType }}',
'{{ definitionBody }}',
'{{ description }}',
'{{ determinismLevel }}',
'{{ importedLibraries }}',
'{{ language }}',
'{{ remoteFunctionOptions }}',
'{{ returnTableType }}',
'{{ returnType }}',
'{{ routineReference }}',
'{{ routineType }}',
'{{ securityMode }}',
'{{ sparkOptions }}',
{{ strictMode }}
;

REPLACE example

Replaces all fields in the specified routines resource.

/*+ update */
REPLACE google.bigquery.routines
SET
arguments = '{{ arguments }}',
dataGovernanceType = '{{ dataGovernanceType }}',
definitionBody = '{{ definitionBody }}',
description = '{{ description }}',
determinismLevel = '{{ determinismLevel }}',
importedLibraries = '{{ importedLibraries }}',
language = '{{ language }}',
remoteFunctionOptions = '{{ remoteFunctionOptions }}',
returnTableType = '{{ returnTableType }}',
returnType = '{{ returnType }}',
routineReference = '{{ routineReference }}',
routineType = '{{ routineType }}',
securityMode = '{{ securityMode }}',
sparkOptions = '{{ sparkOptions }}',
strictMode = true|false
WHERE
+datasetId = '{{ +datasetId }}'
AND +routineId = '{{ +routineId }}'
AND projectId = '{{ projectId }}';

DELETE example

Deletes the specified routines resource.

/*+ delete */
DELETE FROM google.bigquery.routines
WHERE +datasetId = '{{ +datasetId }}'
AND +routineId = '{{ +routineId }}'
AND projectId = '{{ projectId }}';