1.PostgreSQL as a relational database management system
PostgreSQL is a server that stores data in typed tables and enforces the rules you declare on every write — a NULL, or an order for a nonexistent customer, gets refused. It protects correctness, not just accepts SQL.
Key features
- PostgreSQL rejects writes that violate a declared constraint, at write time
- Every column has a type — the server enforces it, not just your application
- Structure is declared once, in the schema, and applies to every future row
- MongoDB and other document stores accept a write app-side validation permits
- MySQL is also relational, but differs in defaults, extensibility and SQL conformance
PostgreSQL next to three other stores
- INSERT arrives — a candidate row
- constraints checked — types, NOT NULL, CHECK, foreign keys
- row stored — only if every rule passed
Command
-- The schema is declared once...
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE
);
-- ...and every later write is checked against it.
INSERT INTO customers (email) VALUES ('a@example.com'); -- accepted
INSERT INTO customers (email) VALUES (NULL); -- rejected: NOT NULLPostgreSQL enforces the constraints you declare on every write — it refuses bad data rather than accepting and storing whatever SQL sends it.