Chapter 22. Tutorial 2: The SQL Language

This chapter provides an overview of how to use SQL to perform simple operations. This tutorial is only intended to be an introduction and is in no way a complete tutorial on SQL. Refer to the Red Hat Database SQL Guide and Reference for complete information on PostgreSQL SQL commands. Also, there are numerous books that have been written on SQL (see the Section called SQL Reference Books in Chapter 23). However, you should be aware that some PostgreSQL language features are extensions to the standard.

In the examples that follow, we assume that you have created a database named mydb, as described in the previous chapter, and have started psql.

Concepts

PostgreSQL is a relational database management system (RDBMS). That means it is a system for managing data stored in relations (tables). The notion of storing data in tables is so commonplace today that it might seem inherently obvious, but there are a number of other ways of organizing databases. Files and directories on Unix-like operating systems form an example of a hierarchical database. A more modern development is the object-oriented database.

A table is a named collection of rows. Each row of a given table has the same set of named columns, and each column is of a specific data type. Whereas columns have a fixed order in each row, it is important to note that SQL makes no guarantee about the order of the rows within a table (although they can be explicitly sorted for display).

Tables are grouped into databases, and a collection of databases managed by a single PostgreSQL server instance constitutes a cluster.