You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: setup-instructions.md
+16-88Lines changed: 16 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,98 +14,26 @@ kernelspec:
14
14
15
15
# Setup instructions
16
16
17
-
To get started with the tutorial, you'll need an interactive Python notebook environment.
17
+
Welcome! It's officially SQL-o-clock!
18
18
19
-
## Option 1: Run in Colab
19
+
For the initial, SQL-only sections of this tutorial, please install the DuckDB command line interface (CLI) and load the tutorial notebooks following the steps below:
20
20
21
-
To get started without any setup required, <atarget="_blank"href="https://colab.research.google.com/github/motherduckdb/sql-tutorial">open the tutorial in Colab</a>.
21
+
## Sections 1 and 2
22
22
23
-
This requires a Google account. If you don't have one, you can <ahref="https://accounts.google.com/signup"target="_blank">sign up</a>, or try the other options below.
23
+
1. Follow the DuckDB CLI installation instructions for your OS and CPU
2. Create a new Python virtual environment and activate it:
32
-
```bash
33
-
python3 -m venv venv
34
-
source venv/bin/activate
35
-
```
36
-
3. Start a local <ahref="https://jupyter.org/install"target="_blank">Jupyter Notebook</a> in the `notebooks` folder:
37
-
```
38
-
cd notebooks
39
-
jupyter notebook .
40
-
```
35
+
For the sections that cover combining SQL and Python, see the installation instructions in section 3.
41
36
42
-
Now you can open the `.ipynb` files accompanying the tutorial and run them cell by cell, add your own cells or make edits where needed.
37
+
## Section 4
43
38
44
-
## Option 3: Run in MotherDuck
45
-
46
-
For the parts that require only SQL, you can run them in the MotherDuck app. To access the app, <ahref="https://app.motherduck.com/?auth_flow=signup"target="_blank">sign up for MotherDuck</a>.
47
-
48
-
Every new account receives a 30-day free trial of the MotherDuck Standard Plan, with no credit card required. After the end of your Standard Plan free trial, your account will automatically move to the MotherDuck Free Plan, no action needed on your part.
49
-
50
-
# How to run SQL queries
51
-
52
-
Throughout this tutorial, we'll show you SQL queries that you can run to inspect and manipulate data with DuckDB. DuckDB offers two database modes: in-memory and file-based. In-memory databases store data in RAM, providing lightning-fast operations but losing data when closed, ideal for temporary processing. File-based databases store data on disk, offering persistence and larger data capacity, suitable for long-term storage and sharing. You can easily switch between modes, allowing flexibility to balance performance and data retention needs.
53
-
54
-
## Jupyter Notebook: in-memory database
55
-
56
-
For the first two sections of this tutorial, we will use an in-memory database, since all examples are self-contained and can easily be re-run if needed.
57
-
58
-
You can run SQL directly in a Jupyter Notebook with a Python kernel by installing and loading the `magic_duckdb` extension:
For the latter part of this tutorial, we will cover data sharing and collaboration. To persist your tables to a file or remote database, you can explicitly create a new connection in Python:
75
-
76
-
```python
77
-
import duckdb
78
-
con = duckdb.connect("my_database.duckdb")
79
-
```
80
-
81
-
In a separate cell, pass the connection object to the magic command with the `-co` option:
82
-
83
-
```python
84
-
%%dql -co con
85
-
CREATETABLE test_table as (SELECT42);
86
-
SELECT*FROM test_table;
87
-
```
88
-
89
-
## MotherDuck
90
-
91
-
You can also run SQL directly in a MotherDuck notebook. After <ahref="https://app.motherduck.com/?auth_flow=signup"target="_blank">signing up</a>, go to <ahref="https://app.motherduck.com/"target="_blank">app.motherduck.com</a> and log in. You'll see a SQL notebook environment where you can create cells, upload CSV files and run SQL queries.
92
-
93
-
Once you have the account and [get the authentication token](https://motherduck.com/docs/key-tasks/authenticating-to-motherduck/#creating-an-access-token), you can interact with your data in MotherDuck through the same Python API:
94
-
95
-
```python
96
-
import duckdb
97
-
con = duckdb.connect(f"md:my_db?motherduck_token={token}")
98
-
```
99
-
100
-
## How to access files
101
-
102
-
In a local Jupyter notebook, you can use the local filesystem with no extra steps.
103
-
104
-
In Google Colab, you can download the files using `!wget <url>` and access them directly. Another option is to mount a folder in Google Drive, which makes all files in that folder available to query under `/content/gdrive/MyDrive` path:
105
-
106
-
```
107
-
from google.colab import drive
108
-
drive.mount('/content/gdrive')
109
-
```
110
-
111
-
In MotherDuck, you can add JSON, CSV or Parquet file directly using the Add Files button in the top left of the UI.
39
+
In preparation for section 4, please [sign up for a free account with MotherDuck](https://app.motherduck.com/?auth_flow=signup)!
0 commit comments