Obsolete Platforms
diff --git a/doc/src/sgml/query.sgml b/doc/src/sgml/query.sgml
index 11b603f652..971be24838 100644
--- a/doc/src/sgml/query.sgml
+++ b/doc/src/sgml/query.sgml
@@ -1,5 +1,5 @@
@@ -8,20 +8,21 @@ $Header: /cvsroot/pgsql/doc/src/sgml/query.sgml,v 1.9 2000/03/31 03:27:41 thomas
The Postgres query language is a variant of
the SQL3 draft next-generation standard. It
- has many extensions such as an extensible type system,
+ has many extensions to SQL92 such as an
+ extensible type system,
inheritance, functions and production rules. These are
- features carried over from the original Postgres query
- language, PostQuel. This section provides an overview
+ features carried over from the original
+ Postgres query
+ language, PostQuel.
+ This section provides an overview
of how to use Postgres
SQL to perform simple operations.
This manual is only intended to give you an idea of our
flavor of SQL and is in no way a complete tutorial on
SQL. Numerous books have been written on
- SQL, including
-
-[MELT93] and [DATE97].
+ SQL92, including
+ and
+ .
You should be aware that some language features
are extensions to the ANSI standard.
@@ -111,22 +112,26 @@ CREATE TABLE weather (
- Note that both keywords and identifiers are case-insensitive; identifiers can become
- case-sensitive by surrounding them with double-quotes as allowed
+ Note that both keywords and identifiers are case-insensitive;
+ identifiers can preserve case by surrounding them with
+ double-quotes as allowed
by SQL92.
- Postgres SQL supports the usual
+ Postgres SQL
+ supports the usual
SQL types int,
float, real, smallint,
char(N),
varchar(N), date, time,
and timestamp, as well as other types of general utility and
a rich set of geometric types. As we will
- see later, Postgres can be customized with an
+ see later, Postgres can be customized
+ with an
arbitrary number of
user-defined data types. Consequently, type names are
not syntactical keywords, except where required to support special
cases in the SQL92 standard.
- So far, the PostgresCREATE command
+ So far, the Postgres
+ CREATE command
looks exactly like
the command used to create a table in a traditional
relational system. However, we will presently see that
@@ -139,7 +144,7 @@ CREATE TABLE weather (
Populating a Class with Instances
- The insert statement is used to populate a class with
+ The INSERT statement is used to populate a class with
instances:
@@ -149,9 +154,10 @@ INSERT INTO weather
- You can also use the copy command to perform load large
+ You can also use the COPY command to perform load large
amounts of data from flat (ASCII) files.
- This is usually faster because the data is read (or written) as a single atomic
+ This is usually faster because the data is read (or written) as a
+ single atomic
transaction directly to or from the target table. An example would be:
@@ -159,7 +165,8 @@ COPY weather FROM '/home/user/weather.txt'
USING DELIMITERS '|';
- where the path name for the source file must be available to the backend server
+ where the path name for the source file must be available to the
+ backend server
machine, not the client, since the backend server reads the file directly.
@@ -170,7 +177,7 @@ COPY weather FROM '/home/user/weather.txt'
The weather class can be queried with normal relational
selection and projection queries. A SQL
- select
+ SELECT
statement is used to do this. The statement is divided into
a target list (the part that lists the attributes to be
returned) and a qualification (the part that specifies
@@ -192,7 +199,8 @@ SELECT * FROM weather;
|Hayward | 37 | 54 | | 11-29-1994 |
+--------------+---------+---------+------+------------+
- You may specify any arbitrary expressions in the target list. For example, you can do:
+ 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;
@@ -200,7 +208,8 @@ SELECT city, (temp_hi+temp_lo)/2 AS temp_avg, date FROM weather;
Arbitrary Boolean operators
- (and, or and not) are
+ (AND, OR and
+ NOT) are
allowed in the qualification of any query. For example,
@@ -235,16 +244,16 @@ SELECT DISTINCT city
Redirecting SELECT Queries
- Any select query can be redirected to a new class
+ Any SELECT query can be redirected to a new class
SELECT * INTO TABLE temp FROM weather;
- This forms an implicit create command, creating a new
+ This forms an implicit CREATE command, creating a new
class temp with the attribute names and types specified
- in the target list of the select into command. We can
+ in the target list of the SELECT INTO command. We can
then, of course, perform any operations on the resulting
class that we can perform on other classes.
@@ -269,7 +278,8 @@ SELECT * INTO TABLE temp FROM weather;
This is only a conceptual model. The actual join may
- be performed in a more efficient manner, but this is invisible to the user.
+ be performed in a more efficient manner, but this is invisible
+ to the user.
@@ -307,16 +317,18 @@ SELECT W1.city, W1.temp_lo AS low, W1.temp_hi AS high,
sometimes recomputes the same target list several times;
this frequently happens when Boolean expressions are connected
with an "or". To remove such duplicates, you must use
- the select distinct statement.
+ the SELECT DISTINCT statement.
- In this case, both W1 and W2 are surrogates for an
+ In this case, both W1 and
+ W2 are surrogates for an
instance of the class weather, and both range over all
instances of the class. (In the terminology of most
- database systems, W1 and W2 are known as range variables.)
+ database systems, W1 and W2
+ are known as range variables.)
A query can contain an arbitrary number of
class names and surrogates.
@@ -326,7 +338,8 @@ SELECT W1.city, W1.temp_lo AS low, W1.temp_hi AS high,
Updates
- You can update existing instances using the update command.
+ You can update existing instances using the
+ UPDATE command.
Suppose you discover the temperature readings are
all off by 2 degrees as of Nov 28, you may update the
data as follow:
@@ -343,7 +356,7 @@ UPDATE weather
Deletions
- Deletions are performed using the delete command:
+ Deletions are performed using the DELETE command:
DELETE FROM weather WHERE city = 'Hayward';
@@ -354,7 +367,7 @@ DELETE FROM weather WHERE city = 'Hayward';
DELETE FROM classname;
- Without a qualification, delete will simply
+ Without a qualification, DELETE will simply
remove all instances of the given class, leaving it
empty. The system will not request confirmation before
doing this.
@@ -365,7 +378,7 @@ DELETE FROM classname;
Using Aggregate Functions
- Like most other query languages,
+ Like most other relational database products,
PostgreSQL supports
aggregate functions.
An aggregate function computes a single result from multiple input rows.
@@ -377,20 +390,20 @@ DELETE FROM classname;
It is important to understand the interaction between aggregates and
- SQL's where and having clauses.
- The fundamental difference between where and
- having is this: where selects
+ SQL's WHERE and HAVING clauses.
+ The fundamental difference between WHERE and
+ HAVING is this: WHERE selects
input rows before groups and aggregates are computed (thus, it controls
which rows go into the aggregate computation), whereas
- having selects group rows after groups and
+ HAVING selects group rows after groups and
aggregates are computed. Thus, the
- where clause may not contain aggregate functions;
+ WHERE clause may not contain aggregate functions;
it makes no sense to try to use an aggregate to determine which rows
will be inputs to the aggregates. On the other hand,
- having clauses always contain aggregate functions.
- (Strictly speaking, you are allowed to write a having
+ HAVING clauses always contain aggregate functions.
+ (Strictly speaking, you are allowed to write a HAVING
clause that doesn't use aggregates, but it's wasteful; the same condition
- could be used more efficiently at the where stage.)
+ could be used more efficiently at the WHERE stage.)
@@ -408,13 +421,17 @@ SELECT max(temp_lo) FROM weather;
SELECT city FROM weather WHERE temp_lo = max(temp_lo);
- but this will not work since the aggregate max() can't be used in
- where. However, as is often the case the query can be
+ but this will not work since the aggregate
+ max can't be used in
+ WHERE. However, as is often the case the query can be
restated to accomplish the intended result; here by using a
subselect:
+
-SELECT city FROM weather WHERE temp_lo = (SELECT max(temp_lo) FROM weather);
+SELECT city FROM weather
+ WHERE temp_lo = (SELECT max(temp_lo) FROM weather);
+
This is OK because the sub-select is an independent computation that
computes its own aggregate separately from what's happening in the outer
select.
@@ -422,24 +439,29 @@ SELECT city FROM weather WHERE temp_lo = (SELECT max(temp_lo) FROM weather);
Aggregates are also very useful in combination with
- group by clauses. For example, we can get the
+ GROUP BY clauses. For example, we can get the
maximum low temperature observed in each city with
+
SELECT city, max(temp_lo)
FROM weather
GROUP BY city;
+
which gives us one output row per city. We can filter these grouped
- rows using having:
+ rows using HAVING:
+
SELECT city, max(temp_lo)
FROM weather
GROUP BY city
HAVING min(temp_lo) < 0;
+
which gives us the same results for only the cities that have some
below-zero readings. Finally, if we only care about cities whose
- names begin with 'P', we might do
+ names begin with "P", we might do
+
SELECT city, max(temp_lo)
FROM weather
@@ -447,11 +469,12 @@ SELECT city, max(temp_lo)
GROUP BY city
HAVING min(temp_lo) < 0;
+
Note that we can apply the city-name restriction in
- where, since it needs no aggregate. This is
- more efficient than adding the restriction to having,
+ WHERE, since it needs no aggregate. This is
+ more efficient than adding the restriction to HAVING,
because we avoid doing the grouping and aggregate calculations
- for all rows that fail the where check.
+ for all rows that fail the WHERE check.
diff --git a/doc/src/sgml/sql.sgml b/doc/src/sgml/sql.sgml
index 1df0a41c8a..e030d4dbf8 100644
--- a/doc/src/sgml/sql.sgml
+++ b/doc/src/sgml/sql.sgml
@@ -1,5 +1,5 @@
@@ -7,18 +7,28 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
- This chapter originally appeared as a part of
+ This chapter introduces the mathematical concepts behind
+ relational databases. It is not required reading, so if you bog
+ down or want to get straight to some simple examples feel free to
+ jump ahead to the next chapter and come back when you have more
+ time and patience. This stuff is supposed to be fun!
+
+
+
+ This material originally appeared as a part of
Stefan Simkovics' Master's Thesis
().
- SQL has become the most popular relational query language.
+ SQL has become the most popular relational query
+ language.
The name SQL is an abbreviation for
Structured Query Language.
In 1974 Donald Chamberlin and others defined the
- language SEQUEL (Structured English Query Language) at IBM
+ language SEQUEL (Structured English Query
+ Language) at IBM
Research. This language was first implemented in an IBM
prototype called SEQUEL-XRM in 1974-75. In 1976-77 a revised version
of SEQUEL called SEQUEL/2 was defined and the name was changed to
@@ -28,13 +38,15 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
A new prototype called System R was developed by IBM in 1977. System R
- implemented a large subset of SEQUEL/2 (now SQL) and a number of
+ implemented a large subset of SEQUEL/2 (now SQL)
+ and a number of
changes were made to SQL during the project.
System R was installed in
a number of user sites, both internal IBM sites and also some selected
customer sites. Thanks to the success and acceptance of System R at
those user sites IBM started to develop commercial products that
- implemented the SQL language based on the System R technology.
+ implemented the SQL language based on the System
+ R technology.
@@ -48,16 +60,20 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
- SQL is also an official standard now. In 1982 the American National
- Standards Institute (ANSI) chartered its Database Committee X3H2 to
+ SQL is also an official standard now. In 1982
+ the American National
+ Standards Institute (ANSI) chartered its
+ Database Committee X3H2 to
develop a proposal for a standard relational language. This proposal
was ratified in 1986 and consisted essentially of the IBM dialect of
SQL. In 1987 this ANSI
standard was also accepted as an international
standard by the International Organization for Standardization
(ISO).
- This original standard version of SQL is often referred to,
- informally, as "SQL/86". In 1989 the original standard was extended
+ This original standard version of SQL is often
+ referred to,
+ informally, as "SQL/86". In 1989 the original
+ standard was extended
and this new standard is often, again informally, referred to as
"SQL/89". Also in 1989, a related standard called
Database Language Embedded SQL
@@ -73,12 +89,14 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
ratified standard - "International Standard ISO/IEC 9075:1992,
Database Language SQL" - in late 1992.
SQL/92 is the version
- normally meant when people refer to "the SQL standard". A detailed
+ normally meant when people refer to "the SQL
+ standard". A detailed
description of SQL/92 is given in
. At the time of
writing this document a new standard informally referred to
as SQL3
- is under development. It is planned to make SQL a Turing-complete
+ is under development. It is planned to make SQL
+ a Turing-complete
language, i.e. all computable queries (e.g. recursive queries) will be
possible. This is a very complex task and therefore the completion of
the new standard can not be expected before 1999.
@@ -100,8 +118,10 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
- A relational database is a database that is perceived by its
- users as a collection of tables (and nothing else but tables).
+ A relational database is a database that is
+ perceived by its
+ users as a collection of tables (and
+ nothing else but tables).
A table consists of rows and columns where each row represents a
record and each column represents an attribute of the records
contained in the table.
@@ -154,13 +174,16 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
- The tables PART and SUPPLIER may be regarded as entities and
- SELLS may be regarded as a relationship between a particular
+ The tables PART and SUPPLIER may be regarded as
+ entities and
+ SELLS may be regarded as a relationship
+ between a particular
part and a particular supplier.
- As we will see later, SQL operates on tables like the ones just
+ As we will see later, SQL operates on tables
+ like the ones just
defined but before that we will study the theory of the relational
model.
@@ -171,7 +194,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
The mathematical concept underlying the relational model is the
- set-theoretic relation which is a subset of the Cartesian
+ set-theoretic relation which is a subset of
+ the Cartesian
product of a list of domains. This set-theoretic relation gives
the model its name (do not confuse it with the relationship from the
Entity-Relationship model).
@@ -184,7 +208,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.7 2000/03/31 03:27:41 thomas E
- SIM98
+
for a more detailed
description). For more information about system catalogs refer to
- DATE.
+ .
@@ -1815,10 +1861,10 @@ The only tuple returned by both parts of the query is the one having $SNO=2$.
For a detailed discussion on embedded SQL
refer to
- [],
- [],
+ ,
+ ,
or
- [].
+ .
diff --git a/doc/src/sgml/start.sgml b/doc/src/sgml/start.sgml
index 5589eca7f3..ccb43fbb0f 100644
--- a/doc/src/sgml/start.sgml
+++ b/doc/src/sgml/start.sgml
@@ -1,250 +1,333 @@
-
-Getting Started
+
+ Getting Started
-
-
-How to begin work with Postgres for a new user.
-
-
+
+
+ How to begin work with Postgres for a new user.
+
+
-
- Some of the steps required to use Postgres
- can be performed by any Postgres user, and some must be done by
- the site database administrator. This site administrator
- is the person who installed the software, created
- the database directories and started the postmaster
- process. This person does not have to be the Unix
- superuser (root)
- or the computer system administrator; a person can install and use
-Postgres without any special accounts or privileges.
-
+
+ Some of the steps required to use Postgres
+ can be performed by any Postgres user, and some must be done by
+ the site database administrator. This site administrator
+ is the person who installed the software, created
+ the database directories and started the
+ postmaster
+ process. This person does not have to be the Unix
+ superuser (root)
+ or the computer system administrator; a person can install and use
+ Postgres without any special accounts or
+ privileges.
+
-
-If you are installing Postgres yourself, then
-refer to the Administrator's Guide for instructions on installation, and return
-to this guide when the installation is complete.
-
+
+ If you are installing Postgres yourself, then
+ refer to the Administrator's Guide for instructions on
+ installation, and return
+ to this guide when the installation is complete.
+
-
- Throughout this manual, any examples that begin with
- the character % are commands that should be typed
- at the Unix shell prompt. Examples that begin with the
- character * are commands in the Postgres query
- language, Postgres SQL.
-
+
+ Throughout this manual, any examples that begin with
+ the character % are commands that should be typed
+ at the Unix shell prompt. Examples that begin with the
+ character * are commands in the Postgres query
+ language, Postgres SQL.
+
-
-Setting Up Your Environment
+
+ Setting Up Your Environment
-
- This section discusses how to set up
- your own environment so that you can use frontend
- applications. We assume Postgres has already been
- successfully installed and started; refer to the Administrator's Guide
-and the installation notes
- for how to install Postgres.
-
+
+ This section discusses how to set up
+ your own environment so that you can use frontend
+ applications. We assume Postgres has
+ already been
+ successfully installed and started; refer to the Administrator's Guide
+ and the installation notes
+ for how to install Postgres.
+
-
-Postgres is a client/server application. As a user,
-you only need access to the client portions of the installation (an example
-of a client application is the interactive monitor psql).
- For simplicity,
- we will assume that Postgres has been installed in the
- directory /usr/local/pgsql. Therefore, wherever
- you see the directory /usr/local/pgsql you should
- substitute the name of the directory where Postgres is
- actually installed.
- All Postgres commands are installed in the directory
- /usr/local/pgsql/bin. Therefore, you should add
- this directory to your shell command path. If you use
- a variant of the Berkeley C shell, such as csh or tcsh,
- you would add
-
+
+ Postgres is a client/server
+ application. As a user,
+ you only need access to the client portions of the installation
+ (an example
+ of a client application is the interactive monitor
+ psql).
+ For simplicity,
+ we will assume that Postgres has been
+ installed in the
+ directory /usr/local/pgsql. Therefore, wherever
+ you see the directory /usr/local/pgsql you should
+ substitute the name of the directory where
+ Postgres is
+ actually installed.
+ All Postgres commands are installed in
+ the directory
+ /usr/local/pgsql/bin. Therefore, you should add
+ this directory to your shell command path. If you use
+ a variant of the Berkeley C shell, such as csh or tcsh,
+ you would add
+
+
% set path = ( /usr/local/pgsql/bin path )
-
- in the .login file in your home directory. If you use
- a variant of the Bourne shell, such as sh, ksh, or
- bash, then you would add
-
+
+
+ in the .login file in your home directory.
+ If you use
+ a variant of the Bourne shell, such as sh, ksh, or
+ bash, then you would add
+
+
% PATH=/usr/local/pgsql/bin:$PATH
% export PATH
-
- to the .profile file in your home directory.
- From now on, we will assume that you have added the
- Postgres bin directory to your path. In addition, we
- will make frequent reference to setting a shell
- variable or setting an environment variable throughout
- this document. If you did not fully understand the
- last paragraph on modifying your search path, you
- should consult the Unix manual pages that describe your
- shell before going any further.
-
+
-
-If your site administrator has not set things up in the
-default way, you may have some more work to do. For example, if the database
- server machine is a remote machine, you
-will need to set the PGHOST environment variable to the name
-of the database server machine. The environment variable
-PGPORT may also have to be set. The bottom line is this: if
-you try to start an application program and it complains
-that it cannot connect to the postmaster,
- you should immediately consult your site administrator to make sure that your
-environment is properly set up.
-
+ to the .profile file in your home directory.
+ From now on, we will assume that you have added the
+ Postgres bin directory to your path.
+ In addition, we
+ will make frequent reference to setting a shell
+ variable or setting an environment
+ variable throughout
+ this document. If you did not fully understand the
+ last paragraph on modifying your search path, you
+ should consult the Unix manual pages that describe your
+ shell before going any further.
+
-
+
+ If your site administrator has not set things up in the
+ default way, you may have some more work to do. For example, if
+ the database
+ server machine is a remote machine, you
+ will need to set the PGHOST environment
+ variable to the name
+ of the database server machine. The environment variable
+ PGPORT may also have to be set. The bottom
+ line is this: if
+ you try to start an application program and it complains
+ that it cannot connect to the postmaster,
+ you should immediately consult your site administrator to make
+ sure that your
+ environment is properly set up.
+
-
-Starting the Interactive Monitor (psql)
+
-
- Assuming that your site administrator has properly
- started the postmaster process and authorized you to
- use the database, you (as a user) may begin to start up
- applications. As previously mentioned, you should add
- /usr/local/pgsql/bin to your shell search path.
- In most cases, this is all you should have to do in
- terms of preparation.
-
+
+ Starting the Interactive Monitor (psql)
-
-As of Postgres v6.3, two different styles of connections
-are supported. The site administrator will have chosen to allow TCP/IP network connections
-or will have restricted database access to local (same-machine) socket connections only.
-These choices become significant if you encounter problems in connecting to a database.
-
+
+ Assuming that your site administrator has properly
+ started the postmaster process and
+ authorized you to
+ use the database, you (as a user) may begin to start up
+ applications. As previously mentioned, you should add
+ /usr/local/pgsql/bin to your shell search path.
+ In most cases, this is all you should have to do in
+ terms of preparation.
+
-
- If you get the following error message from a Postgres
- command (such as psql or createdb):
+
+ Two different styles of connections
+ are supported. The site administrator will have chosen to allow
+ TCP/IP network connections
+ or will have restricted database access to local (same-machine)
+ socket connections only.
+ These choices become significant if you encounter problems in
+ connecting to a database, since you will want to confirm that you
+ are choosing an allowed connection option.
+
-
+
+ If you get the following error message from a
+ Postgres
+ command (such as psql or
+ createdb):
+
+
% psql template1
Connection to database 'postgres' failed.
connectDB() failed: Is the postmaster running and accepting connections
at 'UNIX Socket' on port '5432'?
-
+
-or
+ or
-
+
% psql -h localhost template1
Connection to database 'postgres' failed.
connectDB() failed: Is the postmaster running and accepting TCP/IP
(with -i) connections at 'localhost' on port '5432'?
-
+
- it is usually because (1) the postmaster is not running,
- or (2) you are attempting to connect to the wrong server host.
- If you get the following error message:
+ it is usually because
-
+
+
+
+ the postmaster is not running,
+ or
+
+
+
+
+
+ you are attempting to connect to the wrong server host.
+
+
+
+
+
+
+ If you get the following error message:
+
+
FATAL 1:Feb 17 23:19:55:process userid (2360) != database owner (268)
-
+
- it means that the site administrator started the postmaster
- as the wrong user. Tell him to restart it as
- the Postgres superuser.
-
-
+ it means that the site administrator started the
+ postmaster
+ as the wrong user. Tell him to restart it as
+ the Postgres superuser.
+
+
-
-Managing a Database
+
+ Managing a Database
-
- Now that Postgres is up and running we can create some
- databases to experiment with. Here, we describe the
- basic commands for managing a database.
-
+
+ Now that Postgres is up and running we
+ can create some
+ databases to experiment with. Here, we describe the
+ basic commands for managing a database.
+
-
-Most Postgres
-applications assume that the database name, if not specified, is the same as the name on your computer
-account.
-
+
+ Most Postgres
+ applications assume that the database name, if not specified, is
+ the same as the name on your computer
+ account.
+
-
-If your database administrator has set up your account without database creation privileges,
-then she should have told you what the name of your database is. If this is the case, then you
-can skip the sections on creating and destroying databases.
-
+
+ If your database administrator has set up your account without
+ database creation privileges,
+ then she should have told you what the name of your database is. If
+ this is the case, then you
+ can skip the sections on creating and destroying databases.
+
-
-Creating a Database
+
+ Creating a Database
-
- Let's say you want to create a database named mydb.
+
+ Let's say you want to create a database named
+ mydb.
You can do this with the following command:
-
+
% createdb mydb
-
-
+
+
-
-If you do not have the privileges required to create a database, you will see
-the following:
-
+
+ If you do not have the privileges required to create a database,
+ you will see
+ the following:
+
% createdb mydb
WARN:user "your username" is not allowed to create/destroy databases
createdb: database creation failed on mydb.
-
-
+
+
-
- Postgres allows you to create any number of databases
+
+ Postgres allows you to create any
+ number of databases
at a given site and you automatically become the
- database administrator of the database you just created. Database names must have an alphabetic first
+ database administrator of the database you just created.
+ Database names must have an alphabetic first
character and are limited to 32 characters in length.
Not every user has authorization to become a database
- administrator. If Postgres refuses to create databases
+ administrator. If Postgres refuses to
+ create databases
for you, then the site administrator needs to grant you
permission to create databases. Consult your site
administrator if this occurs.
-
-
+
+
-
-Accessing a Database
+
+ Accessing a Database
-
+
Once you have constructed a database, you can access it
by:
-
-
-
-running the Postgres terminal monitor programs
- (e.g. psql) which allows you to interactively
- enter, edit, and execute SQL commands.
-
-
-
-
- writing a C program using the LIBPQ subroutine
- library. This allows you to submit SQL commands
- from C and get answers and status messages back to
+
+
+
+ Running the Postgres terminal
+ monitor programs
+ (e.g. psql) which allows you to
+ interactively
+ enter, edit, and execute SQL commands.
+
+
+
+
+
+ Using an existing native frontend tool like
+ pgaccess or
+ ApplixWare (via
+ ODBC) to create and manipulate a
+ database.
+
+
+
+
+
+ Using a language like perl or tcl which has a supported
+ interface for Postgres. Some of
+ these languages also have convenient and powerful GUI toolkits
+ which can help you construct custom
+ applications. pgaccess, mentioned
+ above, is one such application written in tk/tcl and can be
+ used as an example.
+
+
+
+
+
+ Writing a C program using
+ the LIBPQ subroutine
+ library. This allows you to submit
+ SQL commands
+ from C and get answers and
+ status messages back to
your program. This interface is discussed further
in The PostgreSQL Programmer's Guide.
-
-
-
+
+
+
-You might want to start up psql,
-to try out the examples in this manual.
- It can be activated for the mydb
+ You might want to start up psql,
+ to try out the examples in this manual.
+ It can be activated for the mydb
database by typing the command:
-
+
% psql mydb
-
+
You will be greeted with the following message:
-
+
Welcome to the POSTGRESQL interactive sql monitor:
Please read the file COPYRIGHT for copyright terms of POSTGRESQL
@@ -254,71 +337,79 @@ Welcome to the POSTGRESQL interactive sql monitor:
You are currently connected to the database: template1
mydb=>
-
-
+
+
-
-This prompt indicates that the terminal monitor is listening
- to you and that you can type SQL queries into a
+
+ This prompt indicates that the terminal monitor is listening
+ to you and that you can type SQL queries into a
workspace maintained by the terminal monitor.
- The psql program responds to escape codes that begin
- with the backslash character, \ For example, you
+ The psql program responds to escape
+ codes that begin
+ with the backslash character, \ For example, you
can get help on the syntax of various
- Postgres SQL commands by typing:
-
+ Postgres SQL
+ commands by typing:
+
mydb=> \h
-
+
+
+
Once you have finished entering your queries into the
workspace, you can pass the contents of the workspace
- to the Postgres server by typing:
-
+ to the Postgres server by typing:
+
mydb=> \g
-
+
This tells the server to process the query. If you
- terminate your query with a semicolon, the \g is not
+ terminate your query with a semicolon, the \g is not
necessary.
- psql will automatically process semicolon terminated queries.
+ psql will automatically process
+ semicolon terminated queries.
To read queries from a file, say myFile, instead of
entering them interactively, type:
-
+
mydb=> \i fileName
-
+
- To get out of psql and return to Unix, type
-
+ To get out of psql and return to Unix, type
+
mydb=> \q
-
+
- and psql will quit and return you to your command
- shell. (For more escape codes, type \h at the monitor
- prompt.)
+ and psql will quit and return
+ you to your command
+ shell. (For more escape codes, type \h at the
+ monitor prompt.)
White space (i.e., spaces, tabs and newlines) may be
- used freely in SQL queries. Single-line comments are denoted by
- --. Everything after the dashes up to the end of the
+ used freely in SQL queries. Single-line
+ comments are denoted by
+ --. Everything after the dashes up to the end of the
line is ignored. Multiple-line comments, and comments within a line,
- are denoted by /* ... */
-
-
-
-
-Destroying a Database
+ are denoted by /* ... */
+
+
-
+
+ Destroying a Database
+
+
If you are the database administrator for the database
- mydb, you can destroy it using the following Unix command:
-
+ mydb, you can destroy it using the
+ following Unix command:
+
% dropdb mydb
-
+
This action physically removes all of the Unix files
associated with the database and cannot be undone, so
this should only be done with a great deal of forethought.
-
-
-
+
+
+
-
+
@@ -11,7 +11,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/y2k.sgml,v 1.5 2000/03/31 03:27:42 th
Written by
Thomas Lockhart
- on 1998-10-22.
+ on 1998-10-22. Updated 2000-03-31.
@@ -25,7 +25,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/y2k.sgml,v 1.5 2000/03/31 03:27:42 th
- The author of this statement, a volunteer on the Postgres
+ The author of this statement, a volunteer on the
+ Postgres
support team since November, 1996, is not aware of
any problems in the Postgres code base related
to time transitions around Jan 1, 2000 (Y2K).