MySQL HeatWave User Guide  /  ...  /  ML_PREDICT_ROW


ML_PREDICT_ROW generates predictions for one or more rows of unlabeled data specified in JSON format. ML_PREDICT_ROW is invoked using a SELECT statement.

A loaded model is required to run ML_PREDICT_ROW. See Section 3.9.3, “Loading Models”.


SELECT ML_PREDICT_ROW(input_data, model_handle);

ML_PREDICT_ROW parameters:

  • input_data: Specifies the data to generate predictions for. A single row of data can be specified explicitly in JSON format:

    SELECT sys.ML_PREDICT_ROW(JSON_OBJECT("column_name", value, "column_name", value, ...), 

    ML_PREDICT_ROW can be run on multiple rows of data by specifying the columns as key-value pairs in JSON format and selecting from a table:

    SELECT sys.ML_PREDICT_ROW(JSON_OBJECT("output_col_name", schema.`input_col_name`, 
    output_col_name", schema.`input_col_name`, ...), model_handle) FROM input_table_name LIMIT N;
  • model_handle: Specifies the model handle or a session variable containing the model handle.

Syntax Examples

  • Running ML_PREDICT_ROW on a single row of data:

    SELECT sys.ML_PREDICT_ROW(JSON_OBJECT("sepal length", 7.3, "sepal width", 2.9, 
    "petal length", 6.3, "petal width", 1.8), @iris_model);
  • Running ML_PREDICT_ROW on five rows of data selected from an input table:

    SELECT sys.ML_PREDICT_ROW(JSON_OBJECT("sepal length", iris_test.`sepal length`, 
    "sepal width", iris_test.`sepal width`, "petal length", iris_test.`petal length`, 
    "petal width", iris_test.`petal width`), @iris_model) 
    FROM ml_data.iris_test LIMIT 5;