Skip to content

Querying

How to query the live DuckDB file from your laptop without exposing a SQL endpoint to the public web. Uses Quack over a separate TCP port, token-authenticated.

Query from your laptop

Fastest: rendered tally with bar chart

export SURVEY_QUACK_TOKEN='<token from Railway env>'
export RAILWAY_QUACK_HOST='XXXXX.proxy.rlwy.net'    # your TCP Proxy host
export RAILWAY_QUACK_PORT='99999'                    # your TCP Proxy port

Show all survey result

make survey-result                          # all surveys

Example output — bars scale to each survey’s top answer, so within-newsletter proportions are visible at a glance:

┌────────────┬─────────┬────────┬────────────────────────────────┐
│ survey_id  │ answer  │ clicks │             chart              │
│  varchar   │ varchar │ int64  │            varchar             │
├────────────┼─────────┼────────┼────────────────────────────────┤
│ 2026-06-11 │ awesome │     42 │ ██████████████████████████████ │
│ 2026-06-11 │ good    │     27 │ ███████████████████▎           │
│ 2026-06-11 │ better  │      8 │ █████▋                         │
│ 2026-06-04 │ awesome │     38 │ ██████████████████████████████ │
│ 2026-06-04 │ good    │     22 │ █████████████████▎             │
│ 2026-06-04 │ better  │     11 │ ████████▋                      │
│ 2026-06-04 │ worse   │      2 │ █▌                             │
└────────────┴─────────┴────────┴────────────────────────────────┘

Or one specific:

make survey-result SURVEY_ID=2026-06-04     # one newsletter only

Looks like this:

┌────────────┬────────────┬────────┬────────────────────────────────┐
│ survey_id  │   answer   │ clicks │             chart              │
│  varchar   │  varchar   │ int64  │            varchar             │
├────────────┼────────────┼────────┼────────────────────────────────┤
│ 2026-06-04 │ worse      │      2 │ ██████████████████████████████ │
│ 2026-06-04 │ best       │      1 │ ███████████████                │
└────────────┴────────────┴────────┴────────────────────────────────┘

Interactive: ad-hoc SQL on the remote DuckDB

make railway-duckdb-connect       # for Railway TCP Proxy host:port
# — or —
make duckdb-connect               # for the FreeBSD path with custom DNS

railway-duckdb-connect drops you at a duckdb prompt with two helpers pre-loaded:

  • remote_votes — view over the remote votes table
  • rq(sql) — table macro that runs arbitrary SQL on the remote
-- Latest 20 clicks
FROM remote_votes ORDER BY ts DESC LIMIT 20;

-- Filter locally after fetching the table
FROM remote_votes WHERE survey_id = '2026-06-04';

-- Aggregate on the server, return small result
FROM rq('SELECT survey_id, answer, count(*) AS n
         FROM votes GROUP BY ALL
         ORDER BY survey_id DESC, n DESC');

Note

The Makefile wraps everything in quack_query because ATTACH 'quack:…' errors with Binder Error: Catalog "s" does not exist! in the Quack build shipped with DuckDB 1.5.3 (extension build 1693647). When the next quack release lands the helpers will switch to a proper ATTACH.

Fallback paths

  • Inside Railway’s container: open a shell from the dashboard, then curl https://install.duckdb.org | sh and ~/.duckdb/cli/latest/duckdb -readonly /var/db/survey/votes.duckdb.
  • FreeBSD: ssh ti "duckdb /var/db/survey/votes.duckdb -c 'FROM votes'".