GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • About
  • Download
  • Documentation
  • Community
  • Developers
  • Support
  • Donate
  • Your account

This view

  • Original page
  • New address

GeezerVison is showing www.postgresql.org — Querying a Table

November 19, 2026: PostgreSQL 19 Released!
Documentation → PostgreSQL 7.1
Unsupported versions: 7.1
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.
PostgreSQL 7.1.3 Documentation
Prev Chapter 4. The Query Language Next

4.5. Querying a Table

The weather table can be queried with normal relational selection and projection queries. A SQL SELECT statement is used to do this. The statement is divided into a target list (the part that lists the columns to be returned) and a qualification (the part that specifies any restrictions). For example, to retrieve all the rows of weather, type:

SELECT * FROM weather;
and the output should be:
+--------------+---------+---------+------+------------+
|city          | temp_lo | temp_hi | prcp | date       |
+--------------+---------+---------+------+------------+
|San Francisco | 46      | 50      | 0.25 | 1994-11-27 |
+--------------+---------+---------+------+------------+
|San Francisco | 43      | 57      | 0    | 1994-11-29 |
+--------------+---------+---------+------+------------+
|Hayward       | 37      | 54      |      | 1994-11-29 |
+--------------+---------+---------+------+------------+
You may specify any arbitrary expressions in the target list. For example, you can do:
SELECT city, (temp_hi+temp_lo)/2 AS temp_avg, date FROM weather;

Arbitrary Boolean operators (AND, OR and NOT) are allowed in the qualification of any query. For example,

SELECT * FROM weather
    WHERE city = 'San Francisco'
    AND prcp > 0.0;
results in:
+--------------+---------+---------+------+------------+
|city          | temp_lo | temp_hi | prcp | date       |
+--------------+---------+---------+------+------------+
|San Francisco | 46      | 50      | 0.25 | 1994-11-27 |
+--------------+---------+---------+------+------------+

As a final note, you can specify that the results of a select can be returned in a sorted order or with duplicate rows removed.

SELECT DISTINCT city
    FROM weather
    ORDER BY city;

Prev Home Next
Populating a Table with Rows Up Redirecting SELECT Queries
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.