r/SQL • • 10h ago

SQLite A 60-second SQL test with three traps. Most AIs I've graded fall for at least one

1 Upvotes

I grade AI models on data questions for a living experiment, and the same three mistakes keep showing up. Here's a pocket version: paste it into whatever AI you use and see how it does. The database is SQLite.
sales (sale_id, amount):
1: 412.75 · 2: 268.40 · 3: 529.99 · 4: 145.20 · 5: 876.10 · 6: 233.65
7: 694.30 · 8: 358.55 · 9: 921.00 · 10: 187.45 · 11: 543.80 · 12: 476.25
returns (sale_id, one row per return event, 25 rows):
2, 5, 9, 2, 7, 3, 2, 11, 5, 12, 9, 4, 2, 7, 10, 5, 1, 9, 12, 4, 11, 8, 10, 13, 13
Task: write SQLite SQL returning exactly two columns: returned_sales (how many sales came back) and total_returned_sales (their total value, each sale counted once), and state the two numbers.
Answers, so you can grade it yourself:
Pass: 11 and 5,413.79, exactly two columns, SQL SQLite can run.
Trap 1: a total of 11,860.19 means it joined and summed, so sale 2 was counted 4 times. Counted twice (or four times).
Trap 2: a count of 12 means it counted sale 13, which is in returns but was never sold.
Trap 3: FETCH FIRST, EXTRACT, or more than two columns: wrong database or didn't follow the order.
On the full-size version of this case (500 return rows, 99 sales returned more than once), the counted-twice error invents $31,490.03. I've watched a model miss it twice in graded matches.
Curious what yours answered. Post the number it gave.


r/SQL • • 17h ago

PostgreSQL Self-hosted alternative to Neon's HTTP driver: query your own Postgres via fetch()

1 Upvotes

Connecting serverless and edge functions to self-hosted PostgreSQL can be tricky. Some runtimes have TCP limitations, and opening database connections on every invocation adds overhead.

Neon offers an HTTP driver for its platform, so I built HTTP PostgreSQL Gateway for self-hosted PostgreSQL.

It runs alongside your database and lets you query it using plain fetch().

  • Persistent PostgreSQL connection pooling
  • Scoped API keys mapped to PostgreSQL roles
  • Async queries for long-running operations, so functions don't have to wait for results
  • Atomic batches and transactions

It doesn't replace PostgreSQL or make queries faster. It handles connections and execution outside your serverless functions.

Security: It accepts client-supplied SQL, so use least-privilege roles and restrict network access. The project is new and hasn't had much external review yet.

Repo: https://github.com/http-postgres/http-postgres

How are you connecting self-hosted PostgreSQL to serverless or edge functions today? Feedback welcome.


r/SQL • • 17h ago

Discussion Database design

Thumbnail reddit.com
1 Upvotes

r/SQL • • 21h ago

Discussion How practical are ERDs when coding?

Post image
0 Upvotes

It was my belief in the beginning of 2025 that this project would help ppl who work with databases. There were three main ideas I thought should be different from how it's been done for decades:

  1. There should be no proprietary syntax.
  2. ERDs must be rendered on the fly while coding (so no need for a separate tool or website)
  3. Cursor on a code segment must render that exact schema instantaneously (vs. rendering giant schemas all at once).

What's you perspective on this in 2026?