Querying
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 portShow all survey result
make survey-result # all surveysExample 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 onlyLooks 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 DNSrailway-duckdb-connect drops you at a duckdb prompt with two helpers
pre-loaded:
remote_votes— view over the remotevotestablerq(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 | shand~/.duckdb/cli/latest/duckdb -readonly /var/db/survey/votes.duckdb. - FreeBSD:
ssh ti "duckdb /var/db/survey/votes.duckdb -c 'FROM votes'".