Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Setup Guide for Students

Getting Started with SQL Homework


Choose Your Setup PathΒΆ

There are two ways to work on assignments. Option A is strongly recommended.

Option A β€” Coder (recommended)Option B β€” Local install
Setup time~5 minutes20–30 minutes (PostgreSQL install)
PostgreSQLPre-installed and runningYou install it
Works onAny browserMac, Linux, Windows
Internet requiredYesNo (after setup)

Coder gives you a fully configured VSCode environment in your browser β€” PostgreSQL is already installed, running, and the database is pre-loaded for each assignment. No installation required.

Step A1 β€” Open the WorkspaceΒΆ

  1. Go to coder.cs.calvin.edu

  2. Log in with your Calvin credentials

  3. Make sure PostgreSQL module is running

  4. Open your workspace (or create one if prompted)

  5. Click Open in VS Code β€” this launches a full VSCode session in your browser with everything already configured

Step A2 β€” Accept the AssignmentΒΆ

  1. Click the invitation link your instructor shared

  2. Click Accept this assignment

  3. Wait a few seconds, then refresh the page

  4. Click the link to your newly created repository

  5. Copy the repository URL (green Code button β†’ copy HTTPS URL)

Step A3 β€” Clone the RepositoryΒΆ

Open the terminal inside the Coder VSCode session and run:

git clone https://github.com/[YOUR-REPO-URL-HERE]
cd [HOMEWORK-NAME]
code .

Step A4 β€” Set Up PythonΒΆ

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

You should see (venv) at the start of your terminal prompt.

Important: Activate the virtual environment every time you open a new terminal window before running any Python commands.

Step A5 β€” Install SQLTools ExtensionsΒΆ

You need two VSCode extensions to connect to the database:

  1. Open the Extensions panel (Ctrl+Shift+X / Cmd+Shift+X)

  2. Search for SQLTools and install it

  3. Search for SQLTools PostgreSQL/Cockroach Driver and install it

  4. Reload VSCode when prompted

Step A6 β€” Connect VSCode to the DatabaseΒΆ

  1. Click the SQLTools icon in the VSCode left sidebar (looks like a database cylinder)

  2. Click Add New Connection

  3. On the Select your database driver screen, click PostgreSQL

  4. Fill in the connection form:

Connection name:  CS354
Server:           localhost
Port:             5432
Database:         [DATABASE NAME]    ← provided in the assignment README
Username:         admin
Password:         admin
  1. Click Test Connection to confirm it works, then Save Connection

  2. The connection will appear in the sidebar β€” click it to connect

  3. A green checkmark confirms you are connected

The database is already populated with data. Skip straight to writing queries.

Step A7 β€” ContinueΒΆ

Jump to Step 7 β€” Explore the Database below. The remaining steps are identical for both options.


πŸ’» Option B β€” Local InstallΒΆ

Use this option if you prefer to work offline or already have PostgreSQL installed.

Step B1 β€” Install ToolsΒΆ

ToolWhat it isDownload
PostgreSQL 16The database engineSee below
GitVersion control to submit your workgit-scm.com
VSCodeCode editorcode.visualstudio.com
SQLToolsVSCode extension to run SQL queriesInstall from VSCode marketplace
SQLTools PostgreSQL DriverConnects SQLTools to PostgreSQLInstall from VSCode marketplace
Python 3.10+Runs the grader locallypython.org

Note for Windows users: After installing Git, use Git Bash as your terminal for all commands in this guide.

Step B2 β€” Install PostgreSQLΒΆ

Mac:

brew install postgresql@16
brew services start postgresql@16

Add PostgreSQL to your PATH (add this line to ~/.zshrc or ~/.bash_profile):

export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"

Then reload your shell:

source ~/.zshrc

Linux (Ubuntu/Debian):

sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql

Windows:

winget install PostgreSQL.PostgreSQL.16

After installation, verify PostgreSQL is running:

psql --version

You should see something like psql (PostgreSQL) 16.x.

Step B3 β€” Accept the AssignmentΒΆ

  1. Click the invitation link your instructor shared

  2. Click Accept this assignment

  3. Wait a few seconds, then refresh the page

  4. Click the link to your newly created repository

  5. Copy the repository URL (green Code button β†’ copy HTTPS URL)

Step B4 β€” Clone the RepositoryΒΆ

git clone https://github.com/[YOUR-REPO-URL-HERE]
cd [HOMEWORK-NAME]
code .

Step B5 β€” Set Up PythonΒΆ

Mac / Linux:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Windows:

python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt

Important: Activate the virtual environment every time you open a new terminal window before running any Python commands.

Step B6 β€” Connect VSCode to the DatabaseΒΆ

  1. Click the SQLTools icon in the VSCode left sidebar

  2. Under Connections, you should see a connection already listed

  3. Click it to connect β€” a green checkmark confirms success

If the connection does not appear automatically:

SQLTools sidebar
β†’ Add new connection
β†’ PostgreSQL
β†’ Fill in:
    Host:     localhost
    Port:     5432
    Database: [DATABASE NAME]
    Username: admin
    Password: admin
β†’ Save connection

Step 7 β€” Explore the DatabaseΒΆ

Before writing queries, take a moment to understand the data.

In the SQLTools sidebar, expand your connection to see the tables. Click any table to see its columns.

You can also run a quick exploration query β€” open any .sql file, type the following, and press the Run button:

-- See all tables
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public';
-- Preview a table (replace 'students' with any table name)
SELECT * FROM students LIMIT 5;

Step 8 β€” Write Your QueriesΒΆ

Each question has its own .sql file (e.g. q1.sql, q2.sql).

Open a question file. You will see something like this:

-- ============================================================
-- Question 1 (10 points)
-- List the name and GPA of all students with a GPA above 3.5
-- Order results by GPA descending
--
-- Expected columns: name, gpa
-- ============================================================

-- Write your query below:

Write your query below the comment block:

-- Write your query below:
SELECT name, gpa
FROM students
WHERE gpa > 3.5
ORDER BY gpa DESC;

To run the query, open the VSCode command bar with Ctrl+Shift+P (Windows/Linux) / Cmd+Shift+P (Mac), then type SQLTools and select SQLTools: Run Selected Query (or Run Current Query if nothing is selected).

You can also use the shortcut Ctrl+E Ctrl+E (Windows/Linux) / Cmd+E Cmd+E (Mac) once SQLTools is connected.

Results appear in a panel at the bottom of the screen.


Step 9 β€” Check Your Score LocallyΒΆ

Before submitting, run the grader to see how many questions you have correct:

python grade.py

On your first run, the grader will automatically create and populate the database for you β€” no setup step required:

Database not found β€” creating and loading data...
βœ… q1: correct   (10 pts)
❌ q2: incorrect  (0 pts)
βœ… q3: correct   (10 pts)
πŸ’₯ q4: error β€” syntax error at or near "FORM"  (0 pts)
⬜ q5: empty file  (0 pts)

Score: 20/50

On subsequent runs the database already exists and it starts grading immediately.

Fix any issues and run grade.py again until you are happy with your score.


Step 10 β€” Submit Your WorkΒΆ

When you are ready to submit:

git add .
git commit -m "completed homework"
git push

GitHub Actions will automatically run the grader on your submission.

To see your results:

Go to your repo on GitHub
β†’ Click the Actions tab
β†’ Click the most recent workflow run
β†’ See βœ… or ❌ per question and your total score

You can push as many times as you want before the deadline. Each push triggers a new grading run.


Resetting the DatabaseΒΆ

The database is created automatically the first time you run grade.py. You only need to reset it if you accidentally modified the data with INSERT, UPDATE, or DELETE and want to start fresh.

Option A (Coder): Contact your instructor to have the database reloaded.

Option B (Local):

bash reset.sh

This drops the database entirely and recreates it from scratch with the original schema and seed data.


Common ProblemsΒΆ

Cannot connect to the database in SQLTools (Option A β€” Coder)ΒΆ

If you see β€œNo connections found”, the connection needs to be created manually β€” follow Step A6 above. Make sure your Coder workspace is running before connecting. If Test Connection fails, try refreshing the page and reopening the workspace.

Cannot connect to the database in SQLTools (Option B β€” Local)ΒΆ

Make sure PostgreSQL is running and the admin role exists:

# Mac (Homebrew)
brew services start postgresql@16
# Linux
sudo systemctl start postgresql
# Windows β€” open the Services panel and start "postgresql-x64-16"

If you get an authentication error, the admin role may not exist yet. Ask your instructor or create it manually:

psql -U postgres -c "CREATE ROLE admin WITH LOGIN PASSWORD 'admin' SUPERUSER;"

pip install failsΒΆ

Make sure your virtual environment is activated β€” you should see (venv) in your terminal prompt. If not:

source venv/bin/activate    # Mac/Linux/Coder
venv\Scripts\activate       # Windows

python grade.py says β€œconnection refused” (Option B)ΒΆ

PostgreSQL is not running β€” grade.py cannot auto-create the database without a running server. Start it first:

# Mac (Homebrew)
brew services start postgresql@16
# Linux
sudo systemctl start postgresql
# Windows β€” open the Services panel and start "postgresql-x64-16"

Then run python grade.py again.

I get πŸ’₯ syntax error on a questionΒΆ

There is a SQL syntax error in your query. Read the error message carefully β€” it usually tells you exactly where the problem is. Common mistakes: typo in a keyword (FORM instead of FROM), missing comma between column names, missing semicolon at the end.

I accidentally pushed with empty query filesΒΆ

No problem β€” just write your queries and push again. Each push creates a new grading run.


Quick ReferenceΒΆ

TaskOption A (Coder)Option B (Local)
Open environmentcoder.cs.calvin.eduOpen VSCode locally
Database setupAutomatic on first python grade.py βœ…Automatic on first python grade.py βœ…
Reset database (if data modified)Contact instructorbash reset.sh
Activate venvsource venv/bin/activatesame (Mac/Linux) / venv\Scripts\activate (Win)
Check your scorepython grade.pypython grade.py
Submitgit add . && git commit -m "msg" && git pushsame

Getting HelpΒΆ

Good luck! 🐘