DuckDB
Installation
Steps taken from this link.
- Run the following script to install DuckDB CLI Utility on Ubuntu server:
sh
wget https://github.com/duckdb/duckdb/releases/download/v0.10.0/duckdb_cli-linux-amd64.zip
sudo apt install unzip -y && unzip duckdb_cli-linux-amd64.zip
sudo mv duckdb /usr/local/bin/Python Installation
Steps taken from this link.
- Create a Python Virtual environment and activate it:
sh
python -m venv ~/.venv && source ~/.venv/bin/activate- Install the following DuckDB python package:
sh
pip install duckdbDatabase Setup
- Log into Python shell:
sh
python- SQL queries can be executed using the
duckdb.sqlfunction:
py
import duckdb
duckdb.sql("SELECT 42").show()- By default, a global in-memory connection will be used. Any data stored in files will be lost after shutting down the program. A connection to a persistent database can be created using the
connectfunction.
py
con = duckdb.connect("/home/piratedev/databases/duck.db")
con.sql("CREATE TABLE integers (i INTEGER)")
con.sql("INSERT INTO integers VALUES (42)")
con.sql("SELECT * FROM integers").show()
con.sql("DROP TABLE integers")
con.close()- To interact with DuckDB using SQL at command line:
shell
duckdb ~/databases/duck.db