Skip to content
·7 min read

PostgreSQL Basics for People Who Have Never Used a Database

Find one booking with SQL, see what a column can store, and try a safe one-row change in a practice database

Share

A customer asks whether their bike repair is confirmed. Your app needs one answer from one saved record. PostgreSQL, often called Postgres, is the database that can store those records and find the right one when the app asks.

Start with two invented bookings. You'll find one by its booking number, then see how you could change just that record in a practice database. You can follow the first example on paper.

How does PostgreSQL organize bookings?

Picture a drawer labeled Bookings in a filing cabinet. In PostgreSQL that drawer is a table. Each folder is a row, one saved booking. The labels that appear on every folder are columns, such as booking number and confirmation status.

Booking numberRepairConfirmed
101Replace brake padsfalse
102Fix a flat tiretrue

If the customer gives you booking 101, look at that row. The repair is Replace brake pads and false means it still needs confirmation. The booking number identifies the row even if two customers bring in bikes for the same repair.

How do you ask for one record?

SQL is the language you use to ask a database a question or give it an instruction. To read a row, SELECT names the columns you want to see, FROM says where to look and WHERE limits the result to the rows that match. Before running a query, say what one row you expect and what would count as the wrong answer. PostgreSQL SELECT reference

How do you try your first read?

If you have a disposable PostgreSQL database already, use a local practice database or a private hosted test project with no connection to your live app. Check the project or server, the database name and the account your editor is using. If you can't confirm the destination, use the table above. You can predict the result without an account or an installation.

Paste the whole block into your practice SQL editor. VALUES supplies the two invented rows inside the query, and WITH gives those rows a name for this one statement. This read needs no existing table and saves no rows. PostgreSQL WITH queries, PostgreSQL VALUES reference

WITH practice_bookings (booking_id, repair, confirmed) AS (
  VALUES
    (101, 'Replace brake pads', false),
    (102, 'Fix a flat tire', true)
)
SELECT booking_id, repair, confirmed
FROM practice_bookings
WHERE booking_id = 101;

Expect one row with booking 101, Replace brake pads and false. PostgreSQL's command-line client can display false as f. Try changing just the number to 102 and predict the result before you run it again. A number absent from the sample returns no rows.

What belongs in each column?

A data type tells PostgreSQL what sort of value a column accepts. Choose it based on what the app will do with the value. For example, keep a booking count as a whole number so the app can add it. Keep a written repair description as text. PostgreSQL data types

TypeWhat you could store
textThe written repair description.
integerA whole number such as the number of bikes in one booking.
booleanWhether the shop confirmed the booking, true or false.
timestamp with time zoneThe moment a booking was confirmed.
uuidA long identifier for a record, if your app uses this form of ID.

PostgreSQL can store a moment and display it in the current session's time zone. Save the shop's named time zone separately if the app needs to remember it. Choosing uuid lets a column hold an identifier. To fill it in automatically, configure a database default or have the app supply one. PostgreSQL date and time types, PostgreSQL UUID type, PostgreSQL column defaults

How do you change just one booking?

UPDATE changes every row that matches its WHERE condition. In this practice table, PRIMARY KEY gives each booking a unique number. That makes booking_id = 101 a check you can reason about before touching a row. PostgreSQL UPDATE reference

Open a fresh connection to the confirmed disposable database with permission to create a temporary table. Make sure there's no transaction already open. A transaction groups several database steps. Run the entire block in that one connection. If your editor can't confirm a fresh connection with no open transaction or can't show the block's result, stick to the earlier read. This block creates a temporary table, inserts the two made-up bookings, changes one and then undoes the practice transaction. If anything fails, stop and close the practice connection. PostgreSQL temporary tables, PostgreSQL transactions

BEGIN;

CREATE TEMP TABLE repair_booking_practice (
  booking_id integer PRIMARY KEY,
  repair text NOT NULL,
  confirmed boolean NOT NULL
) ON COMMIT DROP;

INSERT INTO pg_temp.repair_booking_practice
  (booking_id, repair, confirmed)
VALUES
  (101, 'Replace brake pads', false),
  (102, 'Fix a flat tire', true);

UPDATE pg_temp.repair_booking_practice
SET confirmed = true
WHERE booking_id = 101
RETURNING booking_id, repair, confirmed;

ROLLBACK;

RETURNING shows the changed row before the rollback. Expect only booking 101, now true (or t). pg_temp names the current session's temporary-table area. The final ROLLBACK undoes the whole practice transaction, including the table creation. The booking table in your app is outside this exercise.

What should you check in SQL an assistant writes?

Ask for the table and the exact rows a change would affect. If the change is meant for one booking, preview those rows with a read in your practice database. Check whether the matching field is actually unique. Two bookings can have the same repair description.

If the app takes values from a form, have the database library pass those values as query parameters, meaning it sends the form value separately from the SQL instruction. Validate the business rule too. A valid whole number can still refer to a booking the current customer has no permission to open. OWASP guidance on parameterized queries

What changes when an app connects?

The practice editor lets you see what the database returns. To check access through the normal booking route, use a disposable copy of your app. Before opening it, verify that its database and sign-in connections point only to the intended test resources and that it has no connections to live services. If you can't confirm that, stop at the practice database. Use one known fictional booking and two ordinary test accounts in separate sessions. Check that the account that owns it can open it, and that the other account can't open that same record. An administrator's editor can have broader access than either account. Keep private database credentials on the server or in a service designed to manage them.

If your app uses Supabase's Data API, verify that the tables you expose have the right access grants, PostgreSQL row-level security enabled and policies for the actions your users can take. A grant controls whether a role can perform an operation on the table. A policy controls which rows it can reach. Requests authorized as Supabase's elevated service role bypass those row checks. Keep keys that grant that access out of browser code. When a request carries a signed-in user's own access token, that user's row policies apply. Supabase row-level security, Supabase API keys

How can a booking refer to a customer?

As the app grows, customers and bookings can live in separate tables. A booking stores the customer's ID. A foreign key is a database rule that checks a supplied customer ID against an existing customer row. If every booking must have a customer, the ID also needs a rule that requires a value. These rules help keep records consistent as the app changes. See how a booking links to a customer

What should you try next?

Take one screen you're planning and name the row it needs, the columns it should show and the one value it uses to find the row. Put those in your next request to your coding assistant. You'll have an answer you can check before wiring up a real app.

PJ
Pranay Joshi

20+ years building products at scale. VP of Product & Engineering, startup founder, and AI coach. Helping dreamers turn ideas into reality with vibe coding.