Training and Using Models with SQL in Redshift ML
This lesson explains how Redshift ML lets analysts train and use machine learning models with SQL on data already in the warehouse, without moving data or learning ML tooling.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how CREATE MODEL works with SageMaker AI.
- Identify the ways a model can be created.
- Score data with the SQL function that CREATE MODEL creates.
How Redshift ML works
Redshift ML connects SQL in the warehouse to Amazon SageMaker AI, so analysts can build models without learning machine learning tools. A CREATE MODEL statement names a query that selects the training data, the target column to predict, such as whether a customer churned, and the name of a SQL function that will make predictions.
Redshift then exports the training data to Amazon S3, and SageMaker Autopilot explores the data, chooses an algorithm and trains and tunes a model. The finished model is compiled and deployed into Redshift as a SQL function. Analysts call that function in ordinary queries, for example to score every active customer's churn risk, and the predictions run inside the warehouse, without moving data out or calling an external endpoint.
The following diagram shows how the model is built and used.

Model options
Redshift ML lets analysts create and use machine learning models with SQL, and a model can be created in four ways. With Autopilot (AUTO ON), Redshift and SageMaker AI determine the problem type, such as classification or regression, and try algorithms to find the best model. Alternatively, you can name a specific algorithm, such as XGBoost or K-means, when you know what you need. Bring your own model imports a model already trained in SageMaker AI so it can run inside SQL queries. Large language models in Amazon Bedrock can be called from SQL, for example to summarise or classify text. The following table summarises the options.
| Option | Use |
|---|---|
| Autopilot (AUTO ON) | Redshift and SageMaker choose the problem type and algorithm |
| Specific algorithms | XGBoost, K-means and others chosen explicitly |
| Bring your own model | Use a model trained elsewhere in SageMaker |
| Large language models | Call foundation models in Amazon Bedrock from SQL |
Redshift ML options
Marketing analysts who know SQL but not Python want to score every customer's likelihood of cancelling, using two years of history already in Redshift, and refresh the scores weekly.
A CREATE MODEL statement trains a churn model from the customer history with Autopilot, producing a function such as predict_churn. A weekly scheduled query writes scores with that function to a table that dashboards read. No data leaves the analysts' workflow, and no ML infrastructure is managed.
How does Redshift ML serve predictions?
Show answer
As SQL functions created with CREATE MODEL, which run inside Redshift without moving data.
Exam Tips
Remember for the exam
- Redshift ML trains models with CREATE MODEL and serves predictions as SQL functions.
- SageMaker Autopilot chooses the algorithm when AUTO is on.
- Predictions run inside Redshift without moving data.
- Redshift can call Bedrock foundation models from SQL.
- Redshift ML suits analysts who know SQL but not ML tooling.