Skip to main content

routines

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

Overview​

Nameroutines
TypeResource
Idgoogle.bigquery.routines

Fields​

The following fields are returned by SELECT queries:

NameDatatypeDescription
argumentsarrayOptional.
buildStatusobjectOutput only. The build status of the routine. This field is only applicable to Python UDFs. Preview (id: RoutineBuildStatus)
creationTimestring (int64)Output 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. (DATA_GOVERNANCE_TYPE_UNSPECIFIED, DATA_MASKING)
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. If definition_body references another routine, then that routine must be fully qualified with its project ID.
descriptionstringOptional. The description of the routine, if defined.
determinismLevelstringOptional. The determinism level of the JavaScript UDF, if defined. (DETERMINISM_LEVEL_UNSPECIFIED, DETERMINISTIC, NOT_DETERMINISTIC)
etagstringOutput only. A hash of this resource.
externalRuntimeOptionsobjectOptional. Options for the runtime of the external system executing the routine. This field is only applicable for Python UDFs. Preview (id: ExternalRuntimeOptions)
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. (LANGUAGE_UNSPECIFIED, SQL, JAVASCRIPT, PYTHON, JAVA, SCALA)
lastModifiedTimestring (int64)Output only. The time when this routine was last modified, in milliseconds since the epoch.
pythonOptionsobjectOptional. Options for the Python UDF. Preview (id: PythonOptions)
remoteFunctionOptionsobjectOptional. Remote function specific options. (id: RemoteFunctionOptions)
returnTableTypeobjectOptional. Can be set only if routine_type = "TABLE_VALUED_FUNCTION". If absent, the return table type is inferred from definition_body at query time in each query that references this routine. If present, then the columns in the evaluated table result will be cast to match the column types specified in return table type, at query time. (id: StandardSqlTableType)
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"} } (id: StandardSqlDataType)
routineReferenceobjectId path of a routine. (id: RoutineReference)
routineTypestringRequired. The type of routine. (ROUTINE_TYPE_UNSPECIFIED, SCALAR_FUNCTION, PROCEDURE, TABLE_VALUED_FUNCTION, AGGREGATE_FUNCTION)
securityModestringOptional. The security mode of the routine, if defined. If not defined, the security mode is automatically determined from the routine's configuration. (SECURITY_MODE_UNSPECIFIED, DEFINER, INVOKER)
sparkOptionsobjectOptional. Spark specific options. (id: SparkOptions)
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​

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectprojectId, datasetId, routineIdreadMaskGets the specified routine resource by routine ID. # IAM Permissions Requires the bigquery.routines.get permission on the routine.
listselectprojectId, datasetIdfilter, maxResults, pageToken, readMaskLists all routines in the specified dataset. Requires the READER dataset role. # IAM Permissions Requires the bigquery.routines.list permission on the dataset.
insertinsertprojectId, datasetIdCreates a new routine in the dataset. # IAM Permissions Requires the bigquery.routines.create permission on the dataset.
updatereplaceprojectId, datasetId, routineIdUpdates information in an existing routine. The update method replaces the entire Routine resource. # IAM Permissions Requires the bigquery.routines.update permission on the routine.
deletedeleteprojectId, datasetId, routineIdDeletes the routine specified by routineId from the dataset. # IAM Permissions Requires the bigquery.routines.delete permission on the routine.

Parameters​

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
datasetIdstring
projectIdstring
routineIdstring
filterstring
maxResultsinteger (uint32)
pageTokenstring
readMaskstring (google-fieldmask)

SELECT examples​

Gets the specified routine resource by routine ID. # IAM Permissions Requires the bigquery.routines.get permission on the routine.

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

INSERT examples​

Creates a new routine in the dataset. # IAM Permissions Requires the bigquery.routines.create permission on the dataset.

INSERT INTO google.bigquery.routines (
data__arguments,
data__dataGovernanceType,
data__definitionBody,
data__description,
data__determinismLevel,
data__externalRuntimeOptions,
data__importedLibraries,
data__language,
data__pythonOptions,
data__remoteFunctionOptions,
data__returnTableType,
data__returnType,
data__routineReference,
data__routineType,
data__securityMode,
data__sparkOptions,
data__strictMode,
projectId,
datasetId
)
SELECT
'{{ arguments }}',
'{{ dataGovernanceType }}',
'{{ definitionBody }}',
'{{ description }}',
'{{ determinismLevel }}',
'{{ externalRuntimeOptions }}',
'{{ importedLibraries }}',
'{{ language }}',
'{{ pythonOptions }}',
'{{ remoteFunctionOptions }}',
'{{ returnTableType }}',
'{{ returnType }}',
'{{ routineReference }}',
'{{ routineType }}',
'{{ securityMode }}',
'{{ sparkOptions }}',
{{ strictMode }},
'{{ projectId }}',
'{{ datasetId }}'
RETURNING
arguments,
buildStatus,
creationTime,
dataGovernanceType,
definitionBody,
description,
determinismLevel,
etag,
externalRuntimeOptions,
importedLibraries,
language,
lastModifiedTime,
pythonOptions,
remoteFunctionOptions,
returnTableType,
returnType,
routineReference,
routineType,
securityMode,
sparkOptions,
strictMode
;

REPLACE examples​

Updates information in an existing routine. The update method replaces the entire Routine resource. # IAM Permissions Requires the bigquery.routines.update permission on the routine.

REPLACE google.bigquery.routines
SET
data__arguments = '{{ arguments }}',
data__dataGovernanceType = '{{ dataGovernanceType }}',
data__definitionBody = '{{ definitionBody }}',
data__description = '{{ description }}',
data__determinismLevel = '{{ determinismLevel }}',
data__externalRuntimeOptions = '{{ externalRuntimeOptions }}',
data__importedLibraries = '{{ importedLibraries }}',
data__language = '{{ language }}',
data__pythonOptions = '{{ pythonOptions }}',
data__remoteFunctionOptions = '{{ remoteFunctionOptions }}',
data__returnTableType = '{{ returnTableType }}',
data__returnType = '{{ returnType }}',
data__routineReference = '{{ routineReference }}',
data__routineType = '{{ routineType }}',
data__securityMode = '{{ securityMode }}',
data__sparkOptions = '{{ sparkOptions }}',
data__strictMode = {{ strictMode }}
WHERE
projectId = '{{ projectId }}' --required
AND datasetId = '{{ datasetId }}' --required
AND routineId = '{{ routineId }}' --required
RETURNING
arguments,
buildStatus,
creationTime,
dataGovernanceType,
definitionBody,
description,
determinismLevel,
etag,
externalRuntimeOptions,
importedLibraries,
language,
lastModifiedTime,
pythonOptions,
remoteFunctionOptions,
returnTableType,
returnType,
routineReference,
routineType,
securityMode,
sparkOptions,
strictMode;

DELETE examples​

Deletes the routine specified by routineId from the dataset. # IAM Permissions Requires the bigquery.routines.delete permission on the routine.

DELETE FROM google.bigquery.routines
WHERE projectId = '{{ projectId }}' --required
AND datasetId = '{{ datasetId }}' --required
AND routineId = '{{ routineId }}' --required
;