#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/doc/src/sgml/Makefile,v 1.36 2001/04/20 15:52:33 thomas Exp $
+# $Header: /cvsroot/pgsql/doc/src/sgml/Makefile,v 1.37 2001/05/12 22:51:34 petere Exp $
#
#----------------------------------------------------------------------------
ALLBOOKS = admin developer programmer reference tutorial user
-ALLSGML := $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml)
+ALLSGML := $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml) bookindex.sgml setindex.sgml
-
-catalog: Makefile $(top_builddir)/src/Makefile.global
- (echo "PUBLIC \"-//Norman Walsh//DOCUMENT DocBook HTML Stylesheet//EN\" \"$(DOCBOOKSTYLE)/html/docbook.dsl\""; \
- echo "PUBLIC \"-//Norman Walsh//DOCUMENT DocBook Print Stylesheet//EN\" \"$(DOCBOOKSTYLE)/print/docbook.dsl\"") > $@
-
-ifeq "$(origin DOCBOOKSTYLE)" "command line"
-.PHONY: catalog
-endif
+CATALOG = $(DOCBOOKSTYLE)/catalog
##
## HTML
##
-JADE.html = $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -d stylesheet.dsl -i output-html -t sgml
+JADE.html = $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -c $(CATALOG) -d stylesheet.dsl -i output-html -t sgml
-postgres.html: postgres.sgml $(ALLSGML) stylesheet.dsl catalog
+postgres.html: postgres.sgml $(ALLSGML) stylesheet.dsl
@rm -f *.html
$(JADE.html) $<
ln -sf $@ index.html
-$(addsuffix .html, $(ALLBOOKS)): %.html: %.sgml $(ALLSGML) stylesheet.dsl catalog
+$(addsuffix .html, $(ALLBOOKS)): %.html: %.sgml $(ALLSGML) stylesheet.dsl
@rm -f *.html
$(JADE.html) book-decl.sgml $<
ln -sf $@ index.html
+COLLATEINDEX = $(PERL) $(DOCBOOKSTYLE)/bin/collateindex.pl -f -g -t 'Index'
+
+ifeq (,$(wildcard HTML.index))
+bookindex.sgml:
+ $(COLLATEINDEX) -o $@ -N
+setindex.sgml:
+ $(COLLATEINDEX) -x -o $@ -N
+else
+bookindex.sgml: HTML.index
+ $(COLLATEINDEX) -i 'bookindex' -o $@ $<
+setindex.sgml: HTML.index
+ $(COLLATEINDEX) -i 'setindex' -x -o $@ $<
+endif
+
##
## Print
##
# RTF to allow minor editing for hardcopy
-$(addsuffix .rtf, $(ALLBOOKS)): %.rtf: %.sgml $(ALLSGML) stylesheet.dsl catalog
- $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -d stylesheet.dsl -t rtf -V rtf-backend -i output-print book-decl.sgml $<
+$(addsuffix .rtf, $(ALLBOOKS)): %.rtf: %.sgml $(ALLSGML) stylesheet.dsl
+ $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -c $(CATALOG) -d stylesheet.dsl -t rtf -V rtf-backend -i output-print book-decl.sgml $<
# TeX and DVI
-$(addsuffix .tex, $(ALLBOOKS)): %.tex: %.sgml $(ALLSGML) stylesheet.dsl catalog
- $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -d stylesheet.dsl -t tex -V tex-backend -i output-print book-decl.sgml $<
+$(addsuffix .tex, $(ALLBOOKS)): %.tex: %.sgml $(ALLSGML) stylesheet.dsl
+ $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -c $(CATALOG) -d stylesheet.dsl -t tex -V tex-backend -i output-print book-decl.sgml $<
%.dvi: %.tex
jadetex $<
## Semi-automatic generation of some text files.
##
-JADE.text = $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -d stylesheet.dsl -i output-text -t sgml
+JADE.text = $(JADE) $(JADEFLAGS) $(SGMLINCLUDE) -c $(CATALOG) -d stylesheet.dsl -i output-text -t sgml
INSTALL HISTORY: % : %.html
@echo "|";\
##
clean distclean maintainer-clean:
- rm -f catalog
# HTML
rm -f HTML.manifest *.html
# man
rm -rf *.1 *.$(DEFAULTSECTION) man1 man$(DEFAULTSECTION) manpage.refs manpage.links manpage.log
# print
rm -f *.rtf *.tex *.dvi *.aux *.log *.ps *.pdf
+# index
+ rm -f HTML.index bookindex.sgml setindex.sgml
&biblio;
+ &bookindex;
]]>
-
+
Arrays
+
+
+
Postgres allows columns of a table to be
defined as variable-length multi-dimensional arrays. Arrays of any
-
+
Client Authentication
+
+
+
When a client application connects to the database server, it specifies which
Postgres user name it wants to connect as,
The pg_hba.conf file
+
+
+
Client authentication is controlled by the file
pg_hba.conf in the $PGDATA directory, e.g.,
Password authentication
+
+
+
+
Postgres> database passwords are separate from any
operating system user passwords. Ordinarily, the password for each
Kerberos authentication
+
+
+
Kerberos is an industry-standard secure
authentication system suitable for distributed computing over a
Ident-based authentication
+
+
+
The Identification Protocol
is described in
RFC 1413. Virtually every Unix-like
Ident maps are held in the file pg_ident.conf
in the data directory, which contains lines of the general form:
Data Types
+
+
+
+
+ data types
+
+
Postgres has a rich set of native data
types available to users.
Numeric Types
+
+ numeric
+
+
+
+
+
+
+
+
+
+
+
+
+ integer
+
+
+
+ smallint
+
+
+
+ bigint
+
+
+
+
+
+
+ numeric
+
+
+
+
+
+
+
+
+
+ real
+
+
+
+ double precision
+
+
+
+
+
Numeric types consist of two-, four-, and eight-byte integers,
four- and eight-byte
The Serial Type
+
+
+
+
+ serial
+
+
+
+ and serial type
+
+
The serial type is a special-case type constructed by
Postgres from other existing components.
Character Types
+
+ data types
+
+
+
+ character strings
+
+
+
+ character strings
+
+
SQL defines two primary character types:
character and character varying.
date
+
+
+ data type
+
+
The following are possible inputs for the date type.
time [ without time zone ]
+
+ data type
+
+
Per SQL99, this type can be referenced as time and
as time without time zone.
timestamp
+
+ data type
+
+
Valid input for the timestamp type consists of a concatenation
of a date and a time, followed by an optional AD or
interval
+
+
+
intervals can be specified with the following syntax:
Special values
+
+ current
+
+
+
+ current
+
+
The following
SQL-compatible functions can be used as date or time
input for the corresponding data type: CURRENT_DATE,
Date/Time Output
+
+ output format
+ Formatting
+
+
+
+ output format
+ Formatting
+
+
Output formats can be set to one of the four styles
ISO-8601,
SQL (Ingres), traditional
Time Zones
+
+
+
Postgres endeavors to be compatible with
SQL92 definitions for typical usage.
Boolean Type
+
+ data type
+
+
+
+
+
+
+
+
Point
+
+
+
Points are the fundamental two-dimensional building block for geometric types.
Line Segment
+
+
+
Line segments (lseg) are represented by pairs of points.
Box
+
+
+
Boxes are represented by pairs of points that are opposite
corners of the box.
Path
+
+
+
Paths are represented by connected sets of points. Paths can be "open", where
the first and last points in the set are not connected, and "closed",
Polygon
+
+
+
Polygons are represented by sets of points. Polygons should probably be
considered equivalent to closed paths, but are stored differently
Circle
+
+
+
Circles are represented by a center point and a radius.
Network Address Data Types
+
+ addresses
+
+
Postgres> offers data types to store IP and MAC
addresses. It is preferable to use these types over plain text
inet
+
+
+
The inet type holds an IP host address, and
optionally the identity of the subnet it is in, all in one field.
cidr>
+
+
+
The cidr type holds an IP network specification.
Input and output formats follow Classless Internet Domain Routing
macaddr>>
+
+
+
+
+ macaddr
+
+
The macaddr> type stores MAC addresses, i.e., Ethernet
card hardware addresses (although MAC addresses are used for
Bit String Types
+
+ data type
+
+
Bit strings are strings of 1's and 0's. They can be used to store
or visualize bit masks. There are two SQL bit types:
Time Zones
+
+
+
Postgres must have internal tabular
information for time zone decoding, since there is no *nix standard
-
+
Functions and Operators
+
+
+
+
+
+
Postgres provides a large number of
functions and operators for the built-in data types. Users can also
Logical Operators
+
+ logical
+
+
+
+ operators
+ operators, logical
+
+
The usual logical operators are available:
+
+ operator
+
+
+
+ operator
+
+
+
+ operator
+
+
AND
OR
Comparison Operators
+
+ operators
+
+
Comparison Operators
+
+
In addition to the comparison operators, the special
BETWEEN construct is available.
|
text
- string concatenation
+
+ string concatenation
+
+ concatenation
+
+
'Postgre' || 'SQL'
PostgreSQL
|
char_length(string) or character_length(string)
integer
- length of string
+
+ length of string
+
+ length
+
+
+ character strings
+ character strings, length
+
+
char_length('jose')
4
|
substring(string from integer for integer)
text
- extract substring
+
+ extract substring
+
+
+
substring('Thomas' from 2 for 3)
oma
Pattern Matching with LIKE
+
+
+
string LIKE pattern ESCAPE escape-character
string NOT LIKE pattern ESCAPE escape-character
POSIX Regular Expressions
+
+ pattern matching
+
+
Regular Expression Match Operators
Formatting Functions
+
+
+
Author
- If you want to
- have a double quote in the output you must precede it with a
- backslash, for example '\\"YYYY
- Month\\"'.
+ If you want to have a double quote in the output you must
+ precede it with a backslash, for example '\\"YYYY
+ Month\\"'.
Current Date/Time
+
+ current
+
+
+
+ current
+
+
The following functions are available to obtain the current date and/or
time:
Conditional Expressions
+
+
+
+
+
+
This section describes the
SQL-compliant conditional expressions
NULLIF
+
+
+
NULLIF(value1, value2)
+
+ current
+
+
The session_user> is the user that initiated a database
connection and is fixed for the duration of that connection. The
AVG(expression)
the average (arithmetic mean) of all input values
+
+ function
+
Finding the average value is available on the following data
types: smallint, integer,
bigint, real, double
STDDEV(expression)
the sample standard deviation of the input values
+
+
Finding the standard deviation is available on the following
data types: smallint, integer,
bigint, real, double
VARIANCE(expression)
the sample variance of the input values
+
+
The variance is the square of the standard deviation. The
supported data types are the same.
-
+
Indices
+
+
+
+
+ indices
+
+
Indices are a common way to enhance database performance. An index
allows the database server to find and retrieve specific rows much
Postgres provides several index types:
B-tree, R-tree, and Hash. Each index type is more appropriate for
- a particular query type because of the algorithm it uses. By
+ a particular query type because of the algorithm it uses.
+
+ B-tree
+
+
+ indices
+
+ By
default, the CREATE INDEX command will create a
B-tree index, which fits the most common situations. In
particular, the
Postgres query optimizer
+
+ R-tree
+
+
+ indices
+
R-tree indices are especially suited for spacial data. To create
an R-tree index, use a command of the form
+
+ hash
+
+
+ indices
+
The query optimizer will consider using a hash index whenever an
indexed column is involved in a comparison using the
= operator. The following command is used to
Multi-Column Indices
+
+ multi-column
+
+
An index can be defined on more than one column. For example, if
you have a table of this form:
Unique Indices
+
+ unique
+
+
Indexes may also be used to enforce uniqueness of a column's value,
or the uniqueness of the combined values of more than one column.
Functional Indices
+
+ on functions
+
+
For a functional index, an index is defined
on the result of a function applied to one or more columns of a
Partial Indices
+
+ partial
+
+
Author
+
+ on Windows
+
+
Build, installation, and use instructions for
-
+
PostgreSQL>]]>
Installation Instructions
+
+
+
Short Version
The following prerequisites exist for building
PostgreSQL>:
+
+
+
GNU> make> is required; other
make> programs will not> work.
+
+
+
The
GNU> Readline> library for comfortable
line editing and command history retrieval will automatically be used
+
+
+
+
+
+
+
not> required when building from a released source
+
+ on Windows
+
To build on
Windows NT> or Windows
2000> you need the
Cygwin> and
If You Are Upgrading
+
+
+
The internal data storage format changes with new releases of
PostgreSQL>. Therefore, if you are upgrading an
+
+
+
To dump your database installation, type:
Configuration>
+
+
+
+
The first step of the installation procedure is to configure the
source tree for your system and choose the options you would like.
+
+ SSL
+
+
--with-openssl=DIRECTORY>
Regression Tests
+
+
+
If you want to test the newly built server before you install it,
you can run the regression tests at this point. The regression
Shared Libraries
+
+
+
+
On some systems that have shared libraries (which most systems do)
you need to tell your system how to find the newly installed
Environment Variables
+
+
+
+
If you installed into /usr/local/pgsql> or some other
location that is not searched for programs by default, you need to
+
+ man pages
+
To enable your system to find the
man>
documentation, you need to add a line like the following to a
shell start-up file:
+
+ list of
+
+
lists all tokens that are key words
in the SQL standard and in
PostgreSQL
-
-
pgtcl - TCL Binding Library
+
+
pgtcl - Tcl Binding Library
+
+
+
+
+
+
pgtcl is a tcl package for front-end programs
libpq - C Library
+
+
+
application programmer's interface to
Functions Associated with the COPY Command
+
+ with libpq
+
+
The COPY command in
Postgres has options to read from
or write to the network connection used by libpq.
Environment Variables
+
+
+
The following environment variables can be used to select default
connection parameter values, which will be used by PQconnectdb or
+
+
PGHOST sets the default server name.
If this begins with a slash, it specifies Unix-domain communication
rather than TCP/IP communication; the value is the name of the
+
+
PGPORT sets the default TCP port number or Unix-domain
socket file extension for communicating with the
+
+
PGDATABASE sets the default
+
+
PGUSER
sets the username used to connect to the database and for authentication.
+
+
PGPASSWORD
sets the password used if the backend demands password authentication.
Threading Behavior
+
+ with libpq
+
+
libpq is thread-safe as of
Postgres 7.0, so long as no two threads
Multi-Version Concurrency Control
+
+
+
Multi-Version Concurrency Control
dirty reads
non-repeatable reads
phantom read
+
+
The four isolation levels and the corresponding behaviors are described below.
Read Committed Isolation Level
+
+ read committed
+
+
Read Committed
is the default isolation level in
Postgres.
Serializable Isolation Level
+
+ read serializable
+
+
Serializable provides the highest transaction
isolation. This level emulates serial transaction execution,
Locking and Tables
+
+
+
provides various lock modes to control concurrent
ODBC Interface
+
+
+
Background information originally by Tim Goeke
(or any
ODBC> driver) is that there must exist a
driver manager> on the system where the
ODBC> driver is to be used. There exists a free
-
ODBC> driver for Unix called iODBC>
- which can be obtained via
+
ODBC> driver for Unix called
+
iODBC> which can be obtained via
url="http://www.iodbc.org">http://www.iodbc.org.
Instructions for installing
iODBC> are contained in
the
iODBC> distribution. Having said that, any
ApplixWare
+
+
+
PL/Perl - Perl Procedural Language
+
+
+
+
+
+
PL/Perl allows you to write functions in the Perl programming
language that may be used in SQL queries as if they were built into
In order to build and install PL/Perl if you are installing
Postgres from source then the
must be supplied to the
configure script. PL/Perl requires that, when
libperl library was build as a shared object.
At the time of this writing, this is almost never the case in the
Perl packages that are distributed with the operating systems. A
PL/pgSQL - SQL Procedural Language
+
+
+
PL/pgSQL is a loadable procedural language for the
Postgres database system.
Porting from Oracle PL/SQL
+
+
+
+
+
+
Author
PL/Tcl - TCL Procedural Language
+
+
+
+
+
+
PL/Tcl is a loadable procedural language for the
Trigger Procedures in PL/Tcl
+
+ in PL/Tcl
+
+
Trigger procedures are defined in
Postgres
as functions without
+
+
elog level msg
&programmer;
&reference;
&developer;
+ &setindex;
&xindex;
&indexcost;
&gist;
-
-
-
-
-
- &trigger;
- &spi;
+ &trigger;
+ &spi;
&biblio;
+ &bookindex;
]]>
-
+
Queries
Joined Tables
+
+
+
A joined table is a table derived from two other (real or
derived) tables according to the rules of the particular join
CROSS JOIN
+
+ cross
+
T1 CROSS JOIN T2
Qualified JOINs
+
+ outer
+
+
T1 { INNER | { LEFT | RIGHT | FULL } OUTER } JOIN T2 ON boolean_expression
T1 { INNER | { LEFT | RIGHT | FULL } OUTER } JOIN T2 USING ( join column list )
+
+ natural
+
Finally, NATURAL is a shorthand form of USING: it forms a USING
list consisting of exactly those column names that appear in both
input tables. As with USING, these columns appear only once in
LEFT OUTER JOIN
+
+ left
+
+
First, an INNER JOIN is performed. Then, for each row in T1
that does not satisfy the join condition with any row in
Subqueries
+
+
+
Subqueries specifying a derived table must be enclosed in
parentheses and must be named using an AS
Table and Column Aliases
+
+ table
+
+
+
+ label
+
+
A temporary name can be given to tables and complex table
references to be used for references to the derived table in
WHERE clause
+
+
+
The syntax of the WHERE clause is
GROUP BY and HAVING clauses
+
+
+
After passing the WHERE filter, the derived input table may be
subject to grouping, using the GROUP BY clause, and elimination of
Select Lists
+
+ select list
+
+
As shown in the previous section,
the table expression in the SELECT command
Column Labels
+
+ column
+
+
The entries in the select list can be assigned names for further
processing. The further processing
in this case is
DISTINCT
+
+
+
After the select list has been processed, the result table may
optionally be subject to the elimination of duplicates. The
Combining Queries
+
+
+
+
+
+
+
The results of two queries can be combined using the set operations
union, intersection, and difference. The syntax is
Sorting Rows
+
+
+ query results
+
After a query has produced an output table (after the select list
LIMIT and OFFSET
+
+
+
+
+ with query results
+
+
SELECT select_list FROM table_expression ORDER BY sort_spec LIMIT { number | ALL } OFFSET number
The Postgres user account
+
+
+
As with any other server daemon that is connected to the world at
large, it is advisable to run Postgres under a separate user
Creating a database cluster
+
+
+
+
+ database cluster
+
+
Before you can do anything, you must initialize a database storage
area on disk. We call this a database
+
+
As an alternative to the option, you can set
the environment variable PGDATA.
Starting the database server
+
+
Before anyone can access the database you must start the database
server. The database server is called
postmaster.
+
+
The postmaster also takes a number of other command line options.
For more information see the reference page and below under runtime
configuration. In particular, in order for the postmaster to accept
+
+
This shell syntax can get tedious quickly. Therefore the shell
script wrapper
pg_ctl is provided that
encapsulates some of the tasks. E.g.,
Run-time configuration
+
+ server
+
+
There are a lot of configuration parameters that affect the
behavior of the database system in some way or other. Here we
+
+
The configuration file is reread whenever the postmaster receives
a SIGHUP signal. This signal is also propagated to all running
backend processes, so that running sessions get the new default.
+
+
+
ENABLE_INDEXSCAN (boolean)
+
+
+
ENABLE_SEQSCAN (boolean)
+
+
genetic query optimization
+
+
+ genetic query optimization
+
+
GEQO (boolean)
+
+ timeout
+
+
DEADLOCK_TIMEOUT (integer)
+
+
+
FSYNC (boolean)
+
+
+
SSL (boolean)
Shared Memory and Semaphores
+
+
+
+
+
+
Shared memory and semaphores are collectively referred to as
System V IPC> (together with message queues, which are
The most important shared memory parameter is SHMMAX>,
the maximum size, in bytes, that a shared memory segment can have.
If you get an error message from shmget> along the
Secure TCP/IP Connections with SSL
+
+
+
PostgreSQL> has native support for connections over
Secure TCP/IP Connections with SSH tunnels
+
+
+
Acknowledgement
-
+
(define %html-header-tags%
(list (list "META" '("NAME" "creation") (list "CONTENT" (time->string (time) #t)))))
+(define html-index #t)
+
]]>
SQL Syntax
+
+ SQL
+
+
A description of the general syntax of SQL.
Identifiers and Key Words
+
+
+
+
+ syntax
+
+
Tokens such as SELECT, UPDATE, or
VALUES in the example above are examples of
+
+ SQL commands
+
Identifier and key word names are case insensitive. Therefore
UPDATE MY_TABLE SET A = 5;
+
+ and identifiers
+
There is a second kind of identifier: the delimited
identifier or quoted
identifier. It is formed by enclosing an arbitrary
Constants
+
+
+
There are four kinds of implicitly typed
String Constants
+
+ constants
+
+
+
+ escaping
+
A string constant in SQL is an arbitrary sequence of characters
bounded by single quotes ('
), e.g., 'This
is a string'. SQL allows single quotes to be embedded
Bit String Constants
+
+ constants
+
+
Bit string constants look like string constants with a
B (upper or lower case) immediately before the
Floating Point Constants
+
+ constants
+
+
Floating point constants are accepted in these general forms:
Constants of Other Types
+
+ constants
+
+
A constant of an arbitrary type can be
entered using any one of the following notations:
Array constants
+
+ constants
+
+
The general format of an array constant is the following:
Operators
+
+ syntax
+
+
An operator is a sequence of up to NAMEDATALEN-1
(31 by default) characters from the following list:
Comments
+
+ in SQL
+
+
A comment is an arbitrary sequence of characters beginning with
double dashes and extending to the end of the line, e.g.:
is either a user-defined column of a given table or one of the
following system-defined columns:
+
+ system columns
+
+
oid
+
+
The unique identifier (object ID) of a row. This is a serial number
that is added by Postgres to all rows automatically. OIDs are not
reused and are 32-bit quantities.
Aggregate Expressions
+
+
+
An aggregate expression represents the
application of an aggregate function across the rows selected by a
Lexical Precedence
+
+ precedence
+
+
The precedence and associativity of the operators is hard-wired
into the parser. Most operators have the same precedence and are
&biblio;
+
+ &bookindex;
+ ]]>
+
Extending SQL: Aggregates
+
+ extending
+
+
Aggregate functions in
Postgres
are expressed as state values
+
+
+ extending
+
+
As previously mentioned, there are two kinds of types
in
Postgres: base types (defined in a programming language)