CREATE MODEL

Creates a new machine learning model in the current/specified schema or replaces an existing model.

Note

Use the Snowflake Model Registry Python API to create models from scratch. In SQL, you can only create models from other models.

Models are versioned. All models must have at least one version, and one version must be designated as the default. To add a version to a model, use ALTER MODEL … ADD VERSION.

Some properties of a model can be modified (see ALTER MODEL), and multiple versions can be added.

This command also supports the following variant:

  • CREATE MODEL … FROM internalStage (creates a model from files in an external stage)

See also:

ALTER MODEL , ALTER MODEL … ADD VERSION , DROP MODEL , SHOW MODELS

Syntax

CREATE [ OR REPLACE ] MODEL [ IF NOT EXISTS ] <name> [ WITH VERSION <version_name> ]
    FROM MODEL <source_model_name> [ VERSION <source_version_or_alias_name> ]
Copy

Variant Syntax

This variant is used by the Snowflake Model Registry Python API. It is not possible to create models from scratch in SQL.

CREATE [ OR REPLACE ] MODEL [ IF NOT EXISTS ] <name> FROM internalStage
Copy

Where:

internalStage ::=
    @[<namespace>.]<int_stage_name>[/<path>]
  | @[<namespace>.]%<table_name>[/<path>]
  | @~[/<path>]
Copy

For additional internal stage details, see Choosing an internal stage for local files.

Required parameters

name

String that specifies the identifier (i.e. name) for the new model; must be unique for the schema in which the model is created.

In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

FROM MODEL source_model_name
Required if not using FROM internalStage variant

Specifies the name of the model from which to create the new model.

FROM internalStage
Required if using FROM internalStage variant

Specifies the internal stage that contains the model’s files. The required layout of these files is not currently documented.

Optional parameters

WITH VERSION version_name
For use with FROM MODEL variant

Specifies the name of the version to create in the new model.

VERSION source_version_or_alias_name
For use with FROM MODEL variant

Specifies the name or alias of the version to be copied from the source model. If not specified, uses the default version from the source model.

Access control requirements

A role used to execute this SQL command must have the following privileges at a minimum:

Privilege

Object

Notes

CREATE MODEL

Schema

Implied by USAGE on schema

OWNERSHIP

Model

A role must be granted or inherit the OWNERSHIP privilege on the object to create a temporary object that has the same name as the object that already exists in the schema.

The USAGE privilege on the parent database and schema are required to perform operations on any object in a schema.

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.