How to preserve an analysis or query result in a dataset
Sometimes in CARTO we notice that maps take a lot of time to calculate a layer’s analysis or a custom SQL query result. To improve this, we can materialize our layer
. That means that we store the layer’s result in a new CARTO dataset, instead of calculating it on the fly.
This new dataset can be loaded directly on our map, so the map doesn’t have to consume time automatically calculating that result on the fly when it is opened.
Materialize a Builder map analysis
Follow these steps to materialize a Builder map analysis:
- Open a Builder map that contains an analysis.
- Find the layer that contains your analysis. Click on the three dots located to the right of the layer’s name. A dropdown menu will appear. Select the
Export data
option to download the layer as a new dataset.
- Create a new CARTO dataset from this file by importing it to your account.
- Add this new dataset to your map as a new layer, and delete the original map layer it came from.
We can use this approach to store one or more Builder map layer analyses in a new CARTO dataset.
Materialize Builder map SQL queries
Sometimes we want to use an analysis that isn’t already provided by Builder. For example, we might want to execute a custom spatial analysis using certain PostGIS functions. For these cases, Builder map layers provide an editable SQL panel that we can use to apply our query.
However our custom query’s result might take a long time to calculate, which can delay map rendering. In these cases it can be more efficient to create a new dataset from the query result and use that as a layer in our map.
Take these steps to create a dataset from a SQL query:
- Open a CARTO dataset from your account’s Data dashboard, or by clicking on the blue link under your map layer’s title.
- Set the
Metadata/SQL
toggle to SQL to open your dataset’s editable SQL panel.
- Replace the default query with your custom one and click
Apply
.
- Click on the three dots located to the right of the dataset’s name. A dropdown menu will appear. Select the
Create Dataset
from query option to save the query results as a new dataset.
- Add this new dataset to your map.