Import data with the EdgeSQL Shell
Load a CSV file, a SQL script, or a table from another database into a SQL Database table with the EdgeSQL Shell import commands.
You load data into a SQL Database table with EdgeSQL Shell, from a CSV or XLSX file, a SQL script, a local SQLite database, or a table held by MySQL, PostgreSQL, Kaggle, or Turso. The three local sources read a path on your machine and need no credentials. The four remote sources read theirs from environment variables you export before you start the shell.
For the complete argument form of every command below, the output modes, and the full table of credential variables, refer to EdgeSQL Shell.
Prerequisites
- SQL Database enabled on your account. The product is in Preview and is not enabled by default, so request access through Technical Support.
- EdgeSQL Shell installed, with its virtual environment active. Refer to Install the EdgeSQL Shell.
- A database to import into. Create one as in Create and manage databases, or from the shell itself with
.create <database-name>. - A personal token exported as
AZION_TOKEN. The shell authenticates with it. - The credentials of the source you read from, for the four remote sources. Each section below names the variables its source needs.
Import a CSV or XLSX file
.import file reads a file on your machine and writes its rows into a table. It accepts a CSV or an XLSX file and no other format, and it is the only source whose argument form names a file type. To import a CSV file:
Every command that follows runs against this database.
The last two arguments are the path to the file and the name of the target table. Pass xlsx in place of csv for an Excel file. A three-row file imports in about five seconds.
The shell writes a progress bar while it chunks the data, and ends on one line:
The table holds the rows of the file, and .tables lists it among the tables of the database.
Run a SQL file
.read runs the SQL statements a file holds against the database in use. Use it for a file of INSERT statements, or for a file that creates a schema and fills it in one pass. To run the file:
The shell answers with one line:
The statements have run in the order the file holds them, and the rows they insert are readable with a SELECT at the EdgeSQL> prompt.
Import from a SQLite database
.import sqlite copies one table out of a SQLite database file on your machine. Its arguments are the path to the file, the table to read, and the table to write. To import the table:
The shell answers with one line:
The target table holds the rows of the source table, with their column types preserved.
Import from MySQL
.import mysql reads one table from a MySQL server. It needs MYSQL_USERNAME, MYSQL_PASSWORD, and MYSQL_HOST. MYSQL_PORT is optional, and the MYSQL_SSL_* variables configure a TLS connection. For every variable and its accepted values, refer to Environment variables.
Azion has not run this import. The command form comes from the shell’s own help text, so no output is shown for it. To import the table:
In the terminal, before you start the shell:
<database> is the database on the MySQL server, <source_table> the table to read, and <table_name> the table to write in SQL Database.
The target table holds the rows read from the MySQL table.
Import from PostgreSQL
.import postgres reads one table from a PostgreSQL server. It needs POSTGRES_USERNAME, POSTGRES_PASSWORD, and POSTGRES_HOST. POSTGRES_PORT is optional, and the POSTGRES_SSL_* variables configure a TLS connection. For every variable and its accepted values, refer to Environment variables.
Azion has not run this import. The command form comes from the shell’s own help text, so no output is shown for it. To import the table:
In the terminal, before you start the shell:
<database> is the database on the PostgreSQL server, <source_table> the table to read, and <table_name> the table to write in SQL Database.
The target table holds the rows read from the PostgreSQL table.
Import from Kaggle
.import kaggle reads one file out of a Kaggle dataset. It needs KAGGLE_USERNAME and KAGGLE_KEY, and it is the only source whose arguments name a dataset and a file inside it rather than a database and a table.
Azion has not run this import. The command form comes from the shell’s own help text, so no output is shown for it. Kaggle is also the source that stops the shell from starting: the module behind this command imports the Kaggle package at startup, which is the failure the caution above describes. To import the file:
In the terminal, before you start the shell:
The arguments are the dataset, the file inside it, and the target table. This example is the one the shell’s help text prints.
The target table holds the rows of the file read from the dataset.
Import from Turso
.import turso reads one table from a Turso database. It needs TURSO_DATABASE_URL and TURSO_AUTH_TOKEN, and TURSO_ENCRYPTION_KEY is optional.
Azion has not run this import. The command form comes from the shell’s own help text, so no output is shown for it. To import the table:
In the terminal, before you start the shell:
<database> is the database on the Turso server, <source_table> the table to read, and <table_name> the table to write in SQL Database.
The target table holds the rows read from the Turso table.