which returns:
-+----------+----------+
-|name | altitude |
-+----------+----------+
-|Las Vegas | 2174 |
-+----------+----------+
-|Mariposa | 1953 |
-+----------+----------+
-|Madison | 845 |
-+----------+----------+
+ name | altitude
+-----------+----------
+ Las Vegas | 2174
+ Mariposa | 1953
+ Madison | 845
On the other hand, the following query finds
all the cities that are not state capitals and
- are situated at an altitude of 500ft or higher:
+ are situated at an altitude over 500ft:
SELECT name, altitude
FROM ONLY cities
WHERE altitude > 500;
-+----------+----------+
-|name | altitude |
-+----------+----------+
-|Las Vegas | 2174 |
-+----------+----------+
-|Mariposa | 1953 |
-+----------+----------+
+ name | altitude
+-----------+----------
+ Las Vegas | 2174
+ Mariposa | 1953
which returns:
-+---------+----------+----------+
-|tableoid |name | altitude |
-+---------+----------+----------+
-|37292 |Las Vegas | 2174 |
-+---------+----------+----------+
-|37280 |Mariposa | 1953 |
-+---------+----------+----------+
-|37280 |Madison | 845 |
-+---------+----------+----------+
+ tableoid | name | altitude
+----------+-----------+----------
+ 139793 | Las Vegas | 2174
+ 139793 | Mariposa | 1953
+ 139798 | Madison | 845
- If you do a join with pg_class you can see the actual table name:
+ (If you try to reproduce this example, you will probably get different
+ numeric OIDs.) By doing a join with pg_class you can see the actual table
+ names:
SELECT p.relname, c.name, c.altitude
which returns:
-+---------+----------+----------+
-|relname |name | altitude |
-+---------+----------+----------+
-|capitals |Las Vegas | 2174 |
-+---------+----------+----------+
-|cities |Mariposa | 1953 |
-+---------+----------+----------+
-|cities |Madison | 845 |
-+---------+----------+----------+
+ relname | name | altitude
+----------+-----------+----------
+ cities | Las Vegas | 2174
+ cities | Mariposa | 1953
+ capitals | Madison | 845