How to import data in CARTO
In this tutorial, we’ll provide an overview of the methods that exist and show you which options are best for your data.
In the Carto Dashboard you can upload data in two different ways:
1. Drag and drop your file
You can drag and drop your files onto the CARTO Datasets dashboard, and CARTO will automatically upload your file and create a new CARTO dataset.
In this article from the Help Center you can find detailed information about uploading files into CARTO using drag and drop.
2. Import data from “Add datasets” menu
When you upload data using drag and drop, you can only import local files. If you want to import data into your CARTO account to create a Sync table, import data from Google Drive or the CARTO Data Library, then you would need to open the
Add datasets menu.
In order to open the
Add datasets menu you would need to click the option
New Dataset from the Home or the Data page of the CARTO Dashboard. Once you click on the
New dataset option, the next menu will appear:
From this menu, you can import local files, URLs (with the possibility to create Sync tables), or import data from other sources such as Google Drive and ArcGIS Server.
Also, within this menu you could disable the type guessing option, which is always enabled by default as explained in this article of the Help Center.
It is important to take into account that when you import data using the CARTO Dashboard, behind the scenes CARTO is using the CARTO Import API. This means that the import limits of the CARTO Import API are the same for the CARTO Dashboard.
CARTO Import API
If you need to programmatically import files to CARTO or you would like to have more flexibility in how the files are uploaded, then you could use the CARTO Import API!.
Upload local files or URLs
The CARTO Import API provides more options to define the way in which you want to upload your data. For example, if you upload a file that has the same name as a dataset that already exists in your CARTO account, you can indicate that the importer should overwrite the content of the existing dataset with the content of the file you’re importing.
You can find all the information regarding the CARTO Import API in here.
In addition to uploading files to CARTO, you can also connect your CARTO account to your database. That allows you to import database tables to your CARTO account.
You can find detailed information about the different database connectors that CARTO offers in this section of the CARTO Developer Center.
CARTO SQL API: COPY command
The CARTO Import API is very useful, but due to the fact that it has file size and rows limits for files that you import, it might force you to split your files into smaller ones before importing.
That’s why we recommend using the CARTO SQL API’s COPY command to import big CSV files. That is much faster than the default import process, and you wouldn’t need to split your CSV before importing.
The COPY command also has limits. However, its limits are different than the limits for the CARTO Import API. You can find detailed information about COPY command limits in this section of the CARTO Developer Center.
In order to upload data using the COPY command, you would need to follow the next steps:
- Create a table using the a SQL CREATE TABLE operation, making sure to define column order and type. You can apply this CREATE TABLE command via the CARTO SQL API or within the SQL panel of a dataset in your CARTO account. Follow the steps defined in this section of the CARTO Developer Center.
- If your CSV file is larger than 2GB, compress it to a gzip format (
- Use the CARTO SQL API’s COPY From command to upload the file to CARTO. In this section of the CARTO Developer Center you can find detailed information about using the COPY From command to upload big CSV files into CARTO.
These two libraries provide methods that use the Import API, the SQL API, and other CARTO APIs behind-the-scenes. You can use these methods to define your own workflow for uploading data to your CARTO account.