ogr2ogr and IMPORT INTO.
In the following example, you will import a data set with the locations of bus stops in the cities of Minneapolis and St. Paul, MN (USA) that is made available via gisdata.mn.gov.
Before you begin
To follow along with the example below, you will need the following prerequisites:An
ogr2ogr version of 3.1.0 or higher is required to generate data that can be imported into CockroachDB.- Python 3
-
The bus-stop GeoPackage data:
Step 1. Convert the GeoPackage data to CSV
Convert the GeoPackage data to CSV using the followingogr2ogr command:
Step 2. Host the file where the cluster can access it
Each node in the CockroachDB cluster needs to have access to the files being imported. There are several ways for the cluster to access the data; for a complete list of the types of storageIMPORT INTO can pull from, see Import file location.
For local testing, you can start a local file server. The following command will start a local file server listening on port 3000:
Step 3. Prepare the CockroachDB database
Create a database to hold the bus-stop data:Step 4. Create a CockroachDB table
To import the CSV data, you need to create a table with the necessary columns and data types. Convert the GeoPackage data to SQL using the followingogr2ogr command:
busstops.sql:
Step 5. Import the CSV
Since the file is being served from a local server and is formatted as CSV, you can import the data using the followingIMPORT INTO statement:

