StoicBuilder

HandbookII the ForumSQL queries

IIthe Forum, The shape of an app

SQL queries

1 min readUpdated 28 November

In plain words

SQL is the language Postgres and most other databases understand, and a query is one request written in it, like "give me the ten newest posts".

Where you see it

The SQL Editor in Supabase, or a block in your agent's chat that starts with select. Even when your code uses the Supabase client or an ORM, SQL is what finally reaches the database.

Supabase SQL Editordatabase
select id, content, likesfrom postswhere likes > 100order by created_at desclimit 10;
Read it top to bottom: which columns, from which table, which rows, in what order, how many.

What goes wrong

  1. An update with no where

    Without a where line, an update changes every row in the table, not the one you meant.

    update orders set status = 'cancelled';
  2. Fetching everything and filtering later

    Loading all 50,000 orders and filtering them in JavaScript is slow, and can send rows to the browser that the user shouldn't see. Filter in the query.

  3. Gluing user input into the query

    Building SQL by joining strings lets a visitor slip SQL of their own into it. Use parameters, which the Supabase client and ORMs handle for you.

    `select * from users where email = '${email}'`

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Before running any SQL that updates or deletes rows, show me the query, run a select with the same where clause first, and tell me how many rows it will touch.

Quick check

Sign in to earn +10 XP for it

You ask your agent to cancel order 812, and it runs update orders set status = 'cancelled'. What happened?

Got a prompt that touches SQL queries?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.