-
+
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.
+ chapter, and have
been able to start psql.
This creates the scripts and compiles the C files containing user-defined
- functions and types. (You must use GNU make for this — it may be named
- something different on your system, often
gmake>.)
+ functions and types. (If you installed a pre-packaged version of
+
PostgreSQL rather than building from source,
+ look for a directory named tutorial> within the
+
PostgreSQL documentation. The
make>
+ part should already have been done for you.)
Then, to start the tutorial, do the following:
...
In some database systems, including older versions of
PostgreSQL, the implementation of
DISTINCT automatically orders the rows and
- so ORDER BY is redundant. But this is not
+ so ORDER BY is unnecessary. But this is not
required by the SQL standard, and current
PostgreSQL doesn't guarantee that
DISTINCT causes the rows to be ordered.
Since the columns all had different names, the parser
- automatically found out which table they belong to, but it is good
- style to fully qualify column names in join queries:
+ automatically found out which table they belong to. If there
+ were duplicate column names in the two tables you'd need to
+ qualify> the column names to show which one you
+ meant, as in:
SELECT weather.city, weather.temp_lo, weather.temp_hi,
FROM weather, cities
WHERE cities.name = weather.city;
+
+ It is widely considered good style to qualify all column names
+ in a join query, so that the query won't fail if a duplicate
+ column name is later added to one of the tables.
Now we will figure out how we can get the Hayward records back in.
What we want the query to do is to scan the
weather table and for each row to find the
- matching cities row. If no matching row is
+ matching cities row(s). If no matching row is
found we want some empty values
to be substituted
for the cities table's columns. This kind
of query is called an outer join. (The
but this will not work since the aggregate
max cannot be used in the
WHERE clause. (This restriction exists because
- the WHERE clause determines the rows that will
- go into the aggregation stage; so it has to be evaluated before
- aggregate functions are computed.)
+ the WHERE clause determines which rows will be
+ included in the aggregate calculation; so obviously it has to be evaluated
+ before aggregate functions are computed.)
However, as is often the case
- the query can be restated to accomplish the intended result, here
+ the query can be restated to accomplish the desired result, here
by using a subquery:
You can update existing rows using the
UPDATE command.
Suppose you discover the temperature readings are
- all off by 2 degrees as of November 28. You may update the
+ all off by 2 degrees after November 28. You may correct the
data as follows:
-
+
Getting Started
Another response could be this:
-createdb: could not connect to database postgres: could not connect to server:
-No such file or directory
+createdb: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Another response could be this:
-createdb: could not connect to database postgres: FATAL: user "joe" does not
-exist
+createdb: could not connect to database postgres: FATAL: role "joe" does not exist
where your own login name is mentioned. This will happen if the
administrator has not created a
PostgreSQL> user account
As an explanation for why this works:
PostgreSQL user names are separate
- from operating system user accounts. If you connect to a
+ from operating system user accounts. When you connect to a
database, you can choose what
PostgreSQL user name to connect as;
if you don't, it will default to the same name as your current
That would mean you are a database superuser, which is most likely
the case if you installed
PostgreSQL
yourself. Being a superuser means that you are not subject to
- access controls. For the purpose of this tutorial this is not of
+ access controls. For the purposes of this tutorial that is not of
importance.