

 Amazon Redshift will no longer support the creation of new Python UDFs starting Patch 198. Existing Python UDFs will continue to function until June 30, 2026. For more information, see the [ blog post ](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

# Notebooks in Amazon Redshift
<a name="query-editor-v2-notebooks"></a>

You can use notebooks to organize, annotate, and share multiple SQL queries in a single document. You can add multiple SQL query and Markdown cells to a notebook. Notebooks provide a way to group queries and explanations associated with a data analysis in a single document by using multiple query and Markdown cells. You can add text and format the appearance using Markdown syntax to provide context and additional information for your data analysis tasks. You can share your notebooks with team members.

To use notebooks, you must add permission for notebooks to your IAM principal (an IAM user or IAM role). As a best practice, we recommend attaching permissions policies to an IAM role and then assigning it to users and groups as needed. For more information, see [Identity and access management in Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-authentication-access-control.html). You can add the permission to one of the query editor v2 managed policies. For more information, see [Accessing the query editor v2](query-editor-v2-getting-started.md#query-editor-v2-configure).

You can run all the cells of a notebook sequentially. The SQL query cell of a notebook has most of the same capabilities as a query editor tab. For more information, see [Authoring queries with Amazon Redshift](query-editor-v2-query-run.md). The following are differences between a query editor tab and a SQL cell in a notebook.
+ There isn't a control to run `Explain` on a SQL statement in a notebook.
+ You can create only one chart per SQL cell in a notebook.

You can export and import notebooks to files created with query editor v2. The file extension is `.ipynb` and the file size can be a maximum of 5 MB. The SQL and Markdown cells are stored in the file. A cluster or workgroup and database is not stored in the exported notebook. When you open an imported notebook you choose the cluster or workgroup and the database where to run it. After running SQL cells, you can then choose in the results tab whether to display the current page of results as a chart. The result set of a query is not stored in the notebook.

# Creating a notebook
<a name="query-editor-v2-notebooks-create"></a>

You can create a notebook to organize, annotate, and share multiple SQL queries in a single document. 

**To create a notebook**

1. From the navigator menu, choose the Editor icon (![\[Horizontal lines representing redacted or censored text.\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-align-left.png)).

1. Choose the plus icon (![\[Plus sign icon representing an addition or new item action.\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/add-plus.png)), and then choose **Notebook**.

   By default, a SQL query cell appears in the notebook.

1. In the SQL query cell, do one of the following:
   + Enter a query.
   + Paste a query that you copied.

1. (Optionally) Choose the plus icon (![\[Plus sign icon representing an addition or new item action.\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/add-plus.png)), then choose **Markdown** to add a Markdown cell where you can provide descriptive or explanatory text using standard Markdown syntax. 

1. (Optionally) Choose the plus icon (![\[Plus sign icon representing an addition or new item action.\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/add-plus.png)), then choose **SQL** to insert a SQL cell. 

You can rename notebooks using the pencil icon (![\[Pencil icon representing an editing or writing function.\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-edit.png)).

From the menu icon (![\[Three dots arranged horizontally, representing an ellipsis or "more" menu icon.\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-more.png)), you can also perform the following operations on a notebook:
+ ![\[Share\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-share.png) **Share with my team** – To share the notebook with your team as defined by tags. To share a notebook with your team, make sure that you have the principal tag `sqlworkbench-team` set to the same value as the rest of your team members in your account. For example, an administrator might set the value to `accounting-team` for everyone in the accounting department. For an example, see [Permissions required to use the query editor v2](redshift-iam-access-control-identity-based.md#redshift-policy-resources.required-permissions.query-editor-v2).
+ ![\[Export\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-export.png) **Export** – To export the notebook to a local file with the `.ipynb` extension.
+ ![\[Import query\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-import.png) **Import query** – To import a query from a local file into a cell in the notebook. You can import files with `.sql` and `.txt` extensions.
+  ![\[Save\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-floppy-disk.png) **Save version** – To create a version of the notebook. To see versions of a notebook, navigate to your saved notebooks and open **Version history**.
+  ![\[Duplicate\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-duplicate.png) **Duplicate** – To create a copy of the notebook and open it in a new notebook tab. 
+  ![\[Shortcuts\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-key-command.png) **Shortcuts** – To display the shortcuts available when authoring a notebook. 

# Importing into notebooks
<a name="query-editor-v2-notebooks-import"></a>

You can import an entire notebook or individual SQL cells into a query editor v2 notebook.

To import an entire notebook from a local file to **My notebooks**, choose ![\[Import\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-import.png) **Import**, then choose **Import notebook**. Navigate to the `.ipynb` file that contains your notebook. The notebook is imported into the currently open notebook folder. You can then open the notebook in the notebook editor.

To import a query from a local file into a SQL cell in a notebook, choose ![\[Import\]](http://docs.aws.amazon.com/redshift/latest/mgmt/images/qev2-import.png) **Import**, then choose **Import query**. On the **Import query** window, follow the directions on the screen to choose file and folders that can be imported as a query into a new notebook or an existing notebook. The files must have an extension of `.sql` or `.txt`. Each query can be up to 10,000 characters. When you add to an existing notebook, you choose which notebook from all notebooks in your **Saved notebooks** list. The imported queries are added as SQL cells at the end of the notebook. When you choose a new notebook, you choose the name of the notebook and it is created in the currently open saved notebooks folder. 

**Note**  
When creating `.sql` files on macOS using the TextEdit application, you might encounter an issue where an additional hidden extension is added to the file. For instance, a file named `Test.sql` created in TextEdit might end up being saved as `Test.sql.rtf`. The query editor v2 does not support files with the `.rtf` extension. However, if you create a `.sql` file using TextEdit, and save it as a plain text file, the file has an additional hidden `.txt` extension. For example, a file named `Text.sql` might be saved as `Text.sql.txt`. Unlike the `.rtf` extension, query editor v2 does support files with the `.txt` extension, so `Text.sql.txt` is supported when importing queries to notebooks.

For a demo of notebooks, watch the following video. 

[![AWS Videos](http://img.youtube.com/vi/https://www.youtube.com/embed/GNahyu7j98M/0.jpg)](http://www.youtube.com/watch?v=https://www.youtube.com/embed/GNahyu7j98M)
