HTML 5 - 6.1 : Select a supplier and a public URL
In this video we explore the main data types you will use in PostgreSQL. There are many of them across all RDBMSs, so we will focus on the most common and useful ones. The first group concerns numbers. INT (or INTEGER) is by far the most used type — it stores whole numbers and fits naturally for ages, counts or quantities. The NUMERIC type covers decimal numbers such as 1.50 for a measurement or 19.99 for a price: when you declare it, you give two parameters — the maximum total number of digits and the scale (digits after the decimal point). Last in this group, SERIAL is specific to PostgreSQL: not really a true type, it stores an integer that is automatically incremented starting at 1, which makes it the go-to choice for id columns.
Strings, dates and booleans
Next come string types.CHAR stores fixed-length strings, useful for titles or short acronyms. VARCHAR is the most commonly used string type and stores variable-length strings up to a defined maximum — ideal for names, first names or emails. TEXT is used for unbounded strings, often long, such as comments or product descriptions. For dates, TIME stores hours, minutes and seconds in 24-hour format (rarely used alone), DATE stores dates in YYYY-MM-DD format — useful for a date of birth or a film release — and TIMESTAMP combines both date and time, which is great for orders or deliveries.
- Numeric:
INT,NUMERIC(p, s),SERIAL. - Strings:
CHAR,VARCHAR,TEXT. - Dates / time:
TIME,DATE,TIMESTAMP. - Other:
BOOLEAN,ENUM.
BOOLEAN stores only TRUE or FALSE — handy for flags such as "in stock" — and ENUM stores values from a user-defined list. We declare a list of allowed values and the column can only accept one of those choices; for example, we can build an enum with the days of the week, and any attempt to insert another value such as "September" or "Spring" will raise an error. That covers the main data types in PostgreSQL. In the next video we will look at primary and foreign keys.