Fix indentation of verbatim block elements

Block elements with verbatim formatting (literallayout, programlisting,
screen, synopsis) should be aligned at column 0 independent of the surrounding
SGML, because whitespace is significant, and indenting them creates erratic
whitespace in the output.  The CSS stylesheets already take care of indenting
the output.

Assorted markup improvements to go along with it.
This commit is contained in:
Peter Eisentraut 2010-07-29 19:34:41 +00:00
parent 984d56b80f
commit 66424a2848
55 changed files with 2372 additions and 2478 deletions

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.8 2010/04/03 07:22:52 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.9 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="auto-explain">
<title>auto_explain</title>
@ -19,9 +19,9 @@
The module provides no SQL-accessible functions. To use it, simply
load it into the server. You can load it into an individual session:
<programlisting>
<programlisting>
LOAD 'auto_explain';
</programlisting>
</programlisting>
(You must be superuser to do that.) More typical usage is to preload
it into all sessions by including <literal>auto_explain</> in
@ -163,45 +163,44 @@ LOAD 'auto_explain';
<xref linkend="guc-custom-variable-classes">. Typical usage might be:
</para>
<programlisting>
<programlisting>
# postgresql.conf
shared_preload_libraries = 'auto_explain'
custom_variable_classes = 'auto_explain'
auto_explain.log_min_duration = '3s'
</programlisting>
</programlisting>
</sect2>
<sect2>
<title>Example</title>
<programlisting>
postgres=# LOAD 'auto_explain';
postgres=# SET auto_explain.log_min_duration = 0;
postgres=# SELECT count(*)
FROM pg_class, pg_index
WHERE oid = indrelid AND indisunique;
</programlisting>
<programlisting>
postgres=# LOAD 'auto_explain';
postgres=# SET auto_explain.log_min_duration = 0;
postgres=# SELECT count(*)
FROM pg_class, pg_index
WHERE oid = indrelid AND indisunique;
</programlisting>
<para>
This might produce log output such as:
</para>
<programlisting><![CDATA[
LOG: duration: 3.651 ms plan:
Query Text: SELECT count(*)
FROM pg_class, pg_index
WHERE oid = indrelid AND indisunique;
Aggregate (cost=16.79..16.80 rows=1 width=0) (actual time=3.626..3.627 rows=1 loops=1)
-> Hash Join (cost=4.17..16.55 rows=92 width=0) (actual time=3.349..3.594 rows=92 loops=1)
Hash Cond: (pg_class.oid = pg_index.indrelid)
-> Seq Scan on pg_class (cost=0.00..9.55 rows=255 width=4) (actual time=0.016..0.140 rows=255 loops=1)
-> Hash (cost=3.02..3.02 rows=92 width=4) (actual time=3.238..3.238 rows=92 loops=1)
Buckets: 1024 Batches: 1 Memory Usage: 4kB
-> Seq Scan on pg_index (cost=0.00..3.02 rows=92 width=4) (actual time=0.008..3.187 rows=92 loops=1)
Filter: indisunique
]]>
</programlisting>
<screen><![CDATA[
LOG: duration: 3.651 ms plan:
Query Text: SELECT count(*)
FROM pg_class, pg_index
WHERE oid = indrelid AND indisunique;
Aggregate (cost=16.79..16.80 rows=1 width=0) (actual time=3.626..3.627 rows=1 loops=1)
-> Hash Join (cost=4.17..16.55 rows=92 width=0) (actual time=3.349..3.594 rows=92 loops=1)
Hash Cond: (pg_class.oid = pg_index.indrelid)
-> Seq Scan on pg_class (cost=0.00..9.55 rows=255 width=4) (actual time=0.016..0.140 rows=255 loops=1)
-> Hash (cost=3.02..3.02 rows=92 width=4) (actual time=3.238..3.238 rows=92 loops=1)
Buckets: 1024 Batches: 1 Memory Usage: 4kB
-> Seq Scan on pg_index (cost=0.00..3.02 rows=92 width=4) (actual time=0.008..3.187 rows=92 loops=1)
Filter: indisunique
]]></screen>
</sect2>
<sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/citext.sgml,v 1.4 2010/06/29 22:29:13 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/citext.sgml,v 1.5 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="citext">
<title>citext</title>
@ -22,9 +22,9 @@
in <productname>PostgreSQL</> has been to use the <function>lower</>
function when comparing values, for example
<programlisting>
SELECT * FROM tab WHERE lower(col) = LOWER(?);
</programlisting>
<programlisting>
SELECT * FROM tab WHERE lower(col) = LOWER(?);
</programlisting>
</para>
<para>
@ -74,20 +74,20 @@
<para>
Here's a simple example of usage:
<programlisting>
CREATE TABLE users (
nick CITEXT PRIMARY KEY,
pass TEXT NOT NULL
);
<programlisting>
CREATE TABLE users (
nick CITEXT PRIMARY KEY,
pass TEXT NOT NULL
);
INSERT INTO users VALUES ( 'larry', md5(random()::text) );
INSERT INTO users VALUES ( 'Tom', md5(random()::text) );
INSERT INTO users VALUES ( 'Damian', md5(random()::text) );
INSERT INTO users VALUES ( 'NEAL', md5(random()::text) );
INSERT INTO users VALUES ( 'Bj&oslash;rn', md5(random()::text) );
INSERT INTO users VALUES ( 'larry', md5(random()::text) );
INSERT INTO users VALUES ( 'Tom', md5(random()::text) );
INSERT INTO users VALUES ( 'Damian', md5(random()::text) );
INSERT INTO users VALUES ( 'NEAL', md5(random()::text) );
INSERT INTO users VALUES ( 'Bj&oslash;rn', md5(random()::text) );
SELECT * FROM users WHERE nick = 'Larry';
</programlisting>
SELECT * FROM users WHERE nick = 'Larry';
</programlisting>
The <command>SELECT</> statement will return one tuple, even though
the <structfield>nick</> column was set to <quote>larry</> and the query

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/client-auth.sgml,v 1.139 2010/06/29 22:29:13 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/client-auth.sgml,v 1.140 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="client-authentication">
<title>Client Authentication</title>
@ -1353,11 +1353,11 @@ omicron bryanh guest1
Since LDAP often uses commas and spaces to separate the different
parts of a DN, it is often necessary to use double-quoted parameter
values when configuring LDAP options, for example:
<programlisting>
ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"
</programlisting>
</para>
</note>
<synopsis>
ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"
</synopsis>
</sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.301 2010/07/27 19:01:16 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.302 2010/07/29 19:34:40 petere Exp $ -->
<chapter Id="runtime-config">
<title>Server Configuration</title>
@ -5808,29 +5808,20 @@ plruby.use_strict = true # generates error: unknown class name
type a count of the number of granted locks and waiting locks is
also dumped as well as the totals. An example of the log file output
is shown here:
</para>
<para>
LOG: LockAcquire: new: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(0) req(0,0,0,0,0,0,0)=0 grant(0,0,0,0,0,0,0)=0
wait(0) type(AccessShareLock)
</para>
<para>
LOG: GrantLock: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(2) req(1,0,0,0,0,0,0)=1 grant(1,0,0,0,0,0,0)=1
wait(0) type(AccessShareLock)
</para>
<para>
LOG: UnGrantLock: updated: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(0) req(0,0,0,0,0,0,0)=0 grant(0,0,0,0,0,0,0)=0
wait(0) type(AccessShareLock)
</para>
<para>
LOG: CleanUpLock: deleting: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(0) req(0,0,0,0,0,0,0)=0 grant(0,0,0,0,0,0,0)=0
wait(0) type(INVALID)
</para>
<para>
<screen>
LOG: LockAcquire: new: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(0) req(0,0,0,0,0,0,0)=0 grant(0,0,0,0,0,0,0)=0
wait(0) type(AccessShareLock)
LOG: GrantLock: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(2) req(1,0,0,0,0,0,0)=1 grant(1,0,0,0,0,0,0)=1
wait(0) type(AccessShareLock)
LOG: UnGrantLock: updated: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(0) req(0,0,0,0,0,0,0)=0 grant(0,0,0,0,0,0,0)=0
wait(0) type(AccessShareLock)
LOG: CleanUpLock: deleting: lock(0xb7acd844) id(24688,24696,0,0,0,1)
grantMask(0) req(0,0,0,0,0,0,0)=0 grant(0,0,0,0,0,0,0)=0
wait(0) type(INVALID)
</screen>
Details of the structure being dumped may be found in
src/include/storage/lock.h
</para>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/cube.sgml,v 1.7 2009/12/08 20:08:30 mha Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/cube.sgml,v 1.8 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="cube">
<title>cube</title>
@ -98,47 +98,46 @@
<para>
The <filename>cube</> module includes a GiST index operator class for
<type>cube</> values.
The operators supported by the GiST opclass include:
The operators supported by the GiST opclass are shown in <xref linkend="cube-gist-operators">.
</para>
<itemizedlist>
<listitem>
<programlisting>
a = b Same as
</programlisting>
<para>
The cubes a and b are identical.
</para>
</listitem>
<listitem>
<programlisting>
a &amp;&amp; b Overlaps
</programlisting>
<para>
The cubes a and b overlap.
</para>
</listitem>
<listitem>
<programlisting>
a @&gt; b Contains
</programlisting>
<para>
The cube a contains the cube b.
</para>
</listitem>
<listitem>
<programlisting>
a &lt;@ b Contained in
</programlisting>
<para>
The cube a is contained in the cube b.
</para>
</listitem>
</itemizedlist>
<table id="cube-gist-operators">
<title>Cube GiST operators</title>
<tgroup cols="2">
<thead>
<row>
<entry>Operator</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>a = b</></entry>
<entry>The cubes a and b are identical.</entry>
</row>
<row>
<entry><literal>a &amp;&amp; b</></entry>
<entry>The cubes a and b overlap.</entry>
</row>
<row>
<entry><literal>a @&gt; b</></entry>
<entry>The cube a contains the cube b.</entry>
</row>
<row>
<entry><literal>a &lt;@ b</></entry>
<entry>The cube a is contained in the cube b.</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
(Before PostgreSQL 8.2, the containment operators @&gt; and &lt;@ were
respectively called @ and ~. These names are still available, but are
(Before PostgreSQL 8.2, the containment operators <literal>@&gt;</> and <literal>&lt;@</> were
respectively called <literal>@</> and <literal>~</>. These names are still available, but are
deprecated and will eventually be retired. Notice that the old names
are reversed from the convention formerly followed by the core geometric
datatypes!)
@ -147,10 +146,28 @@ a &lt;@ b Contained in
<para>
The standard B-tree operators are also provided, for example
<programlisting>
[a, b] &lt; [c, d] Less than
[a, b] &gt; [c, d] Greater than
</programlisting>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Operator</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>[a, b] &lt; [c, d]</literal></entry>
<entry>Less than</entry>
</row>
<row>
<entry><literal>[a, b] &gt; [c, d]</literal></entry>
<entry>Greater than</entry>
</row>
</tbody>
</tgroup>
</informaltable>
These operators do not make a lot of sense for any practical
purpose but sorting. These operators first compare (a) to (c),

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.254 2010/07/27 19:01:16 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.255 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="datatype">
<title>Data Types</title>
@ -1584,21 +1584,21 @@ SELECT E'\\xDEADBEEF';
<para>
The <type>interval</type> type has an additional option, which is
to restrict the set of stored fields by writing one of these phrases:
<programlisting>
YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
YEAR TO MONTH
DAY TO HOUR
DAY TO MINUTE
DAY TO SECOND
HOUR TO MINUTE
HOUR TO SECOND
MINUTE TO SECOND
</programlisting>
<literallayout class="monospaced">
YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
YEAR TO MONTH
DAY TO HOUR
DAY TO MINUTE
DAY TO SECOND
HOUR TO MINUTE
HOUR TO SECOND
MINUTE TO SECOND
</literallayout>
Note that if both <replaceable>fields</replaceable> and
<replaceable>p</replaceable> are specified, the
<replaceable>fields</replaceable> must include <literal>SECOND</>,
@ -3811,7 +3811,7 @@ SELECT to_tsvector('english', 'The Fat Rats');
of the operators:
<programlisting>
SELECT 'fat &amp; rat'::tsquery;
SELECT 'fat &amp; rat'::tsquery;
tsquery
---------------
'fat' &amp; 'rat'

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.93 2010/04/06 02:18:04 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.94 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="ddl">
<title>Data Definition</title>
@ -2520,7 +2520,7 @@ CREATE TABLE measurement_y2008m01 ( ) INHERITS (measurement);
just creating the partition tables as above, the table creation
script should really be:
<programlisting>
<programlisting>
CREATE TABLE measurement_y2006m02 (
CHECK ( logdate &gt;= DATE '2006-02-01' AND logdate &lt; DATE '2006-03-01' )
) INHERITS (measurement);
@ -2545,7 +2545,7 @@ CREATE TABLE measurement_y2008m01 (
<para>
We probably need indexes on the key columns too:
<programlisting>
<programlisting>
CREATE INDEX measurement_y2006m02_logdate ON measurement_y2006m02 (logdate);
CREATE INDEX measurement_y2006m03_logdate ON measurement_y2006m03 (logdate);
...

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/dict-xsyn.sgml,v 1.3 2009/08/05 18:06:49 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/dict-xsyn.sgml,v 1.4 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="dict-xsyn">
<title>dict_xsyn</title>
@ -64,9 +64,9 @@
<para>
Each line represents a group of synonyms for a single word, which is
given first on the line. Synonyms are separated by whitespace, thus:
<programlisting>
<programlisting>
word syn1 syn2 syn3
</programlisting>
</programlisting>
</para>
</listitem>
<listitem>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/ecpg.sgml,v 1.100 2010/05/13 14:16:41 mha Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ecpg.sgml,v 1.101 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="ecpg">
<title><application>ECPG</application> - Embedded <acronym>SQL</acronym> in C</title>
@ -2857,11 +2857,11 @@ struct sqlname
the dollar sign instead of the <literal>EXEC SQL</> primitive to introduce
embedded SQL commands.:
<programlisting>
$int j = 3;
$CONNECT TO :dbname;
$CREATE TABLE test(i INT PRIMARY KEY, j INT);
$INSERT INTO test(i, j) VALUES (7, :j);
$COMMIT;
$int j = 3;
$CONNECT TO :dbname;
$CREATE TABLE test(i INT PRIMARY KEY, j INT);
$INSERT INTO test(i, j) VALUES (7, :j);
$COMMIT;
</programlisting>
</para>
<para>
@ -2898,11 +2898,11 @@ struct sqlname
supported in Informix-mode without using <literal>typedef</literal>. In fact, in Informix-mode,
ECPG refuses to process source files that contain <literal>typedef sometype string;</literal>
<programlisting>
EXEC SQL BEGIN DECLARE SECTION;
string userid; /* this variable will contain trimmed data */
EXEC SQL END DECLARE SECTION;
EXEC SQL BEGIN DECLARE SECTION;
string userid; /* this variable will contain trimmed data */
EXEC SQL END DECLARE SECTION;
EXEC SQL FETCH MYCUR INTO :userid;
EXEC SQL FETCH MYCUR INTO :userid;
</programlisting>
</para>
</sect2>
@ -2918,8 +2918,8 @@ struct sqlname
This statement closes the current connection. In fact, this is a
synonym for ecpg's <literal>DISCONNECT CURRENT</>.:
<programlisting>
$CLOSE DATABASE; /* close the current connection */
EXEC SQL CLOSE DATABASE;
$CLOSE DATABASE; /* close the current connection */
EXEC SQL CLOSE DATABASE;
</programlisting>
</para>
</listitem>
@ -3083,15 +3083,15 @@ typedef struct sqlda_compat sqlda_t;
Pointer to the field data. The pointer is of <literal>char *</literal> type,
the data pointed by it is in a binary format. Example:
<programlisting>
int intval;
int intval;
switch (sqldata->sqlvar[i].sqltype)
{
case SQLINTEGER:
switch (sqldata->sqlvar[i].sqltype)
{
case SQLINTEGER:
intval = *(int *)sqldata->sqlvar[i].sqldata;
break;
...
}
...
}
</programlisting>
</para>
</listitem>
@ -3106,8 +3106,8 @@ typedef struct sqlda_compat sqlda_t;
that the value for this field is non-NULL. Otherwise a valid pointer and <literal>sqlitype</literal>
has to be properly set. Example:
<programlisting>
if (*(int2 *)sqldata->sqlvar[i].sqlind != 0)
printf("value is NULL\n");
if (*(int2 *)sqldata->sqlvar[i].sqlind != 0)
printf("value is NULL\n");
</programlisting>
</para>
</listitem>
@ -5208,13 +5208,13 @@ EXEC SQL UPDATE Tbl SET col = MYNUMBER;
<para>
Example:
<programlisting>
exec sql ifndef TZVAR;
exec sql SET TIMEZONE TO 'GMT';
exec sql elif TZNAME;
exec sql SET TIMEZONE TO TZNAME;
exec sql else;
exec sql SET TIMEZONE TO TZVAR;
exec sql endif;
EXEC SQL ifndef TZVAR;
EXEC SQL SET TIMEZONE TO 'GMT';
EXEC SQL elif TZNAME;
EXEC SQL SET TIMEZONE TO TZNAME;
EXEC SQL else;
EXEC SQL SET TIMEZONE TO TZVAR;
EXEC SQL endif;
</programlisting>
</para>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.521 2010/07/03 17:21:48 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.522 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="functions">
<title>Functions and Operators</title>
@ -8228,9 +8228,9 @@ SELECT xmlcomment('hello');
<primary>xmlconcat</primary>
</indexterm>
<synopsis>
<function>xmlconcat</function>(<replaceable>xml</replaceable><optional>, ...</optional>)
</synopsis>
<synopsis>
<function>xmlconcat</function>(<replaceable>xml</replaceable><optional>, ...</optional>)
</synopsis>
<para>
The function <function>xmlconcat</function> concatenates a list
@ -8286,8 +8286,8 @@ SELECT xmlconcat('<?xml version="1.1"?><foo/>', '<?xml version="1.1" standalone=
</indexterm>
<synopsis>
<function>xmlelement</function>(name <replaceable>name</replaceable> <optional>, xmlattributes(<replaceable>value</replaceable> <optional>AS <replaceable>attname</replaceable></optional> <optional>, ... </optional>)</optional> <optional><replaceable>, content, ...</replaceable></optional>)
</synopsis>
<function>xmlelement</function>(name <replaceable>name</replaceable> <optional>, xmlattributes(<replaceable>value</replaceable> <optional>AS <replaceable>attname</replaceable></optional> <optional>, ... </optional>)</optional> <optional><replaceable>, content, ...</replaceable></optional>)
</synopsis>
<para>
The <function>xmlelement</function> expression produces an XML
@ -8383,9 +8383,9 @@ SELECT xmlelement(name foo, xmlattributes('xyz' as bar),
<primary>xmlforest</primary>
</indexterm>
<synopsis>
<function>xmlforest</function>(<replaceable>content</replaceable> <optional>AS <replaceable>name</replaceable></optional> <optional>, ...</optional>)
</synopsis>
<synopsis>
<function>xmlforest</function>(<replaceable>content</replaceable> <optional>AS <replaceable>name</replaceable></optional> <optional>, ...</optional>)
</synopsis>
<para>
The <function>xmlforest</function> expression produces an XML
@ -8440,9 +8440,9 @@ WHERE table_schema = 'pg_catalog';
<primary>xmlpi</primary>
</indexterm>
<synopsis>
<function>xmlpi</function>(name <replaceable>target</replaceable> <optional>, <replaceable>content</replaceable></optional>)
</synopsis>
<synopsis>
<function>xmlpi</function>(name <replaceable>target</replaceable> <optional>, <replaceable>content</replaceable></optional>)
</synopsis>
<para>
The <function>xmlpi</function> expression creates an XML
@ -8469,9 +8469,9 @@ SELECT xmlpi(name php, 'echo "hello world";');
<primary>xmlroot</primary>
</indexterm>
<synopsis>
<function>xmlroot</function>(<replaceable>xml</replaceable>, version <replaceable>text</replaceable> | no value <optional>, standalone yes|no|no value</optional>)
</synopsis>
<synopsis>
<function>xmlroot</function>(<replaceable>xml</replaceable>, version <replaceable>text</replaceable> | no value <optional>, standalone yes|no|no value</optional>)
</synopsis>
<para>
The <function>xmlroot</function> expression alters the properties

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/fuzzystrmatch.sgml,v 1.5 2009/04/06 15:43:00 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/fuzzystrmatch.sgml,v 1.6 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="fuzzystrmatch">
<title>fuzzystrmatch</title>
@ -34,10 +34,10 @@
for working with Soundex codes:
</para>
<programlisting>
soundex(text) returns text
difference(text, text) returns int
</programlisting>
<synopsis>
soundex(text) returns text
difference(text, text) returns int
</synopsis>
<para>
The <function>soundex</> function converts a string to its Soundex code.
@ -53,7 +53,7 @@
Here are some usage examples:
</para>
<programlisting>
<programlisting>
SELECT soundex('hello world!');
SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
@ -70,7 +70,7 @@ INSERT INTO s VALUES ('jack');
SELECT * FROM s WHERE soundex(nm) = soundex('john');
SELECT * FROM s WHERE difference(s.nm, 'john') &gt; 2;
</programlisting>
</programlisting>
</sect2>
<sect2>
@ -80,10 +80,10 @@ SELECT * FROM s WHERE difference(s.nm, 'john') &gt; 2;
This function calculates the Levenshtein distance between two strings:
</para>
<programlisting>
levenshtein(text source, text target, int ins_cost, int del_cost, int sub_cost) returns int
levenshtein(text source, text target) returns int
</programlisting>
<synopsis>
levenshtein(text source, text target, int ins_cost, int del_cost, int sub_cost) returns int
levenshtein(text source, text target) returns int
</synopsis>
<para>
Both <literal>source</literal> and <literal>target</literal> can be any
@ -97,7 +97,7 @@ SELECT * FROM s WHERE difference(s.nm, 'john') &gt; 2;
Examples:
</para>
<programlisting>
<screen>
test=# SELECT levenshtein('GUMBO', 'GAMBOL');
levenshtein
-------------
@ -109,7 +109,7 @@ test=# SELECT levenshtein('GUMBO', 'GAMBOL', 2,1,1);
-------------
3
(1 row)
</programlisting>
</screen>
</sect2>
<sect2>
@ -125,9 +125,9 @@ test=# SELECT levenshtein('GUMBO', 'GAMBOL', 2,1,1);
This function calculates the metaphone code of an input string:
</para>
<programlisting>
metaphone(text source, int max_output_length) returns text
</programlisting>
<synopsis>
metaphone(text source, int max_output_length) returns text
</synopsis>
<para>
<literal>source</literal> has to be a non-null string with a maximum of
@ -140,13 +140,13 @@ test=# SELECT levenshtein('GUMBO', 'GAMBOL', 2,1,1);
Example:
</para>
<programlisting>
<screen>
test=# SELECT metaphone('GUMBO', 4);
metaphone
-----------
KM
(1 row)
</programlisting>
</screen>
</sect2>
<sect2>
@ -160,10 +160,10 @@ test=# SELECT metaphone('GUMBO', 4);
These functions compute the primary and alternate codes:
</para>
<programlisting>
dmetaphone(text source) returns text
dmetaphone_alt(text source) returns text
</programlisting>
<synopsis>
dmetaphone(text source) returns text
dmetaphone_alt(text source) returns text
</synopsis>
<para>
There is no length limit on the input strings.
@ -173,13 +173,13 @@ test=# SELECT metaphone('GUMBO', 4);
Example:
</para>
<programlisting>
<screen>
test=# select dmetaphone('gumbo');
dmetaphone
------------
KMP
(1 row)
</programlisting>
</screen>
</sect2>
</sect1>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/hstore.sgml,v 1.12 2010/07/02 20:36:49 rhaas Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/hstore.sgml,v 1.13 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="hstore">
<title>hstore</title>
@ -24,11 +24,11 @@
includes zero or more <replaceable>key</> <literal>=&gt;</>
<replaceable>value</> pairs separated by commas. Some examples:
<programlisting>
k =&gt; v
foo =&gt; bar, baz =&gt; whatever
"1-a" =&gt; "anything at all"
</programlisting>
<synopsis>
k =&gt; v
foo =&gt; bar, baz =&gt; whatever
"1-a" =&gt; "anything at all"
</synopsis>
The order of the pairs is not significant (and may not be reproduced on
output). Whitespace between pairs or around the <literal>=&gt;</> sign is
@ -42,23 +42,23 @@
with duplicate keys, only one will be stored in the <type>hstore</> and
there is no guarantee as to which will be kept:
<programlisting>
% select 'a=&gt;1,a=&gt;2'::hstore;
<programlisting>
SELECT 'a=&gt;1,a=&gt;2'::hstore;
hstore
----------
"a"=&gt;"1"
</programlisting>
</programlisting>
</para>
<para>
A value (but not a key) can be an SQL <literal>NULL</>. For example:
<programlisting>
key =&gt; NULL
</programlisting>
<programlisting>
key =&gt; NULL
</programlisting>
The <literal>NULL</> keyword is case-insensitive. Double-quote the
<literal>NULL</> to treat it as the ordinary string "NULL".
<literal>NULL</> to treat it as the ordinary string <quote>NULL</quote>.
</para>
<note>
@ -421,11 +421,11 @@ b
<type>hstore</> has GiST and GIN index support for the <literal>@&gt;</>,
<literal>?</>, <literal>?&amp;</> and <literal>?|</> operators. For example:
</para>
<programlisting>
<programlisting>
CREATE INDEX hidx ON testhstore USING GIST (h);
CREATE INDEX hidx ON testhstore USING GIN (h);
</programlisting>
</programlisting>
<para>
<type>hstore</> also supports <type>btree</> or <type>hash</> indexes for
@ -436,11 +436,11 @@ CREATE INDEX hidx ON testhstore USING GIN (h);
may be useful for equivalence lookups. Create indexes for <literal>=</>
comparisons as follows:
</para>
<programlisting>
<programlisting>
CREATE INDEX hidx ON testhstore USING BTREE (h);
CREATE INDEX hidx ON testhstore USING HASH (h);
</programlisting>
</programlisting>
</sect2>
<sect2>
@ -448,22 +448,21 @@ CREATE INDEX hidx ON testhstore USING HASH (h);
<para>
Add a key, or update an existing key with a new value:
</para>
<programlisting>
<programlisting>
UPDATE tab SET h = h || ('c' =&gt; '3');
</programlisting>
</programlisting>
</para>
<para>
Delete a key:
</para>
<programlisting>
<programlisting>
UPDATE tab SET h = delete(h, 'k1');
</programlisting>
</programlisting>
</para>
<para>
Convert a <type>record</> to an <type>hstore</>:
</para>
<programlisting>
<programlisting>
CREATE TABLE test (col1 integer, col2 text, col3 text);
INSERT INTO test VALUES (123, 'foo', 'bar');
@ -472,12 +471,12 @@ SELECT hstore(t) FROM test AS t;
---------------------------------------------
"col1"=&gt;"123", "col2"=&gt;"foo", "col3"=&gt;"bar"
(1 row)
</programlisting>
</programlisting>
</para>
<para>
Convert an <type>hstore</> to a predefined <type>record</> type:
</para>
<programlisting>
<programlisting>
CREATE TABLE test (col1 integer, col2 text, col3 text);
SELECT * FROM populate_record(null::test,
@ -486,12 +485,12 @@ SELECT * FROM populate_record(null::test,
------+------+------
456 | zzz |
(1 row)
</programlisting>
</programlisting>
</para>
<para>
Modify an existing record using the values from an <type>hstore</>:
</para>
<programlisting>
<programlisting>
CREATE TABLE test (col1 integer, col2 text, col3 text);
INSERT INTO test VALUES (123, 'foo', 'bar');
@ -500,7 +499,8 @@ SELECT (r).* FROM (SELECT t #= '"col3"=&gt;"baz"' AS r FROM test t) s;
------+------+------
123 | foo | baz
(1 row)
</programlisting>
</programlisting>
</para>
</sect2>
<sect2>
@ -515,22 +515,21 @@ SELECT (r).* FROM (SELECT t #= '"col3"=&gt;"baz"' AS r FROM test t) s;
<para>
Simple example:
</para>
<programlisting>
<programlisting>
SELECT * FROM each('aaa=&gt;bq, b=&gt;NULL, ""=&gt;1');
</programlisting>
</programlisting>
</para>
<para>
Using a table:
</para>
<programlisting>
<programlisting>
SELECT (each(h)).key, (each(h)).value INTO stat FROM testhstore;
</programlisting>
</programlisting>
</para>
<para>
Online statistics:
</para>
<programlisting>
<programlisting>
SELECT key, count(*) FROM
(SELECT (each(h)).key FROM testhstore) AS stat
GROUP BY key
@ -547,7 +546,8 @@ SELECT key, count(*) FROM
title | 190
org | 189
...................
</programlisting>
</programlisting>
</para>
</sect2>
<sect2>
@ -572,16 +572,16 @@ SELECT key, count(*) FROM
performance penalty when processing data that has not yet been modified by
the new code. It is possible to force an upgrade of all values in a table
column by doing an <literal>UPDATE</> statement as follows:
</para>
<programlisting>
<programlisting>
UPDATE tablename SET hstorecol = hstorecol || '';
</programlisting>
</programlisting>
</para>
<para>
Another way to do it is:
<programlisting>
<programlisting>
ALTER TABLE tablename ALTER hstorecol TYPE hstore USING hstorecol || '';
</programlisting>
</programlisting>
The <command>ALTER TABLE</> method requires an exclusive lock on the table,
but does not result in bloating the table with old row versions.
</para>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.33 2010/02/08 04:33:51 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.34 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="indexam">
<title>Index Access Method Interface Definition</title>
@ -1027,16 +1027,16 @@ amcostestimate (PlannerInfo *root,
Compute the index access cost. A generic estimator might do this:
<programlisting>
/*
* Our generic assumption is that the index pages will be read
* sequentially, so they cost seq_page_cost each, not random_page_cost.
* Also, we charge for evaluation of the indexquals at each index row.
* All the costs are assumed to be paid incrementally during the scan.
*/
cost_qual_eval(&amp;index_qual_cost, indexQuals, root);
*indexStartupCost = index_qual_cost.startup;
*indexTotalCost = seq_page_cost * numIndexPages +
(cpu_index_tuple_cost + index_qual_cost.per_tuple) * numIndexTuples;
/*
* Our generic assumption is that the index pages will be read
* sequentially, so they cost seq_page_cost each, not random_page_cost.
* Also, we charge for evaluation of the indexquals at each index row.
* All the costs are assumed to be paid incrementally during the scan.
*/
cost_qual_eval(&amp;index_qual_cost, indexQuals, root);
*indexStartupCost = index_qual_cost.startup;
*indexTotalCost = seq_page_cost * numIndexPages +
(cpu_index_tuple_cost + index_qual_cost.per_tuple) * numIndexTuples;
</programlisting>
However, the above does not account for amortization of index reads

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/install-win32.sgml,v 1.58 2010/07/27 19:01:16 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/install-win32.sgml,v 1.59 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="install-win32">
<title>Installation from Source Code on <productname>Windows</productname></title>
@ -102,9 +102,9 @@
and then apply any changes from <filename>config.pl</filename>. For example,
to specify the location of your <productname>Python</productname> installation,
put the following in <filename>config.pl</filename>:
<screen>
$config->{python} = 'c:\python26';
</screen>
<programlisting>
$config->{python} = 'c:\python26';
</programlisting>
You only need to specify those parameters that are different from what's in
<filename>config_default.pl</filename>.
</para>
@ -114,9 +114,9 @@
<filename>buildenv.pl</filename> and put the required commands there. For
example, to add the path for bison when it's not in the PATH, create a file
containing:
<screen>
$ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
</screen>
<programlisting>
$ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
</programlisting>
</para>
<sect2>
@ -292,43 +292,31 @@
<para>
To build all of PostgreSQL in release configuration (the default), run the
command:
<screen>
<userinput>
build
</userinput>
</screen>
<screen>
<userinput>build</userinput>
</screen>
To build all of PostgreSQL in debug configuration, run the command:
<screen>
<userinput>
build DEBUG
</userinput>
</screen>
<screen>
<userinput>build DEBUG</userinput>
</screen>
To build just a single project, for example psql, run the commands:
<screen>
<userinput>
build psql
</userinput>
<userinput>
build DEBUG psql
</userinput>
</screen>
<screen>
<userinput>build psql</userinput>
<userinput>build DEBUG psql</userinput>
</screen>
To change the default build configuration to debug, put the following
in the <filename>buildenv.pl</filename> file:
<screen>
<userinput>
$ENV{CONFIG}="Debug";
</userinput>
</screen>
<programlisting>
$ENV{CONFIG}="Debug";
</programlisting>
</para>
<para>
It is also possible to build from inside the Visual Studio GUI. In this
case, you need to run:
<screen>
<userinput>
perl mkvcbuild.pl
</userinput>
</screen>
<screen>
<userinput>perl mkvcbuild.pl</userinput>
</screen>
from the command prompt, and then open the generated
<filename>pgsql.sln</filename> (in the root directory of the source tree)
in Visual Studio.
@ -354,11 +342,9 @@
<filename>debug</filename> or <filename>release</filename> directories. To
install these files using the standard layout, and also generate the files
required to initialize and use the database, run the command:
<screen>
<userinput>
install c:\destination\directory
</userinput>
</screen>
<screen>
<userinput>install c:\destination\directory</userinput>
</screen>
</para>
</sect2>
@ -373,28 +359,18 @@
the <filename>buildenv.pl</filename> file. To run the tests, run one of
the following commands from the <filename>src\tools\msvc</filename>
directory:
<screen>
<userinput>
vcregress check
</userinput>
<userinput>
vcregress installcheck
</userinput>
<userinput>
vcregress plcheck
</userinput>
<userinput>
vcregress contribcheck
</userinput>
</screen>
<screen>
<userinput>vcregress check</userinput>
<userinput>vcregress installcheck</userinput>
<userinput>vcregress plcheck</userinput>
<userinput>vcregress contribcheck</userinput>
</screen>
To change the schedule used (default is parallel), append it to the
command line like:
<screen>
<userinput>
vcregress check serial
</userinput>
</screen>
<screen>
<userinput>vcregress check serial</userinput>
</screen>
For more information about the regression tests, see
<xref linkend="regress">.
@ -448,9 +424,9 @@
</variablelist>
Edit the <filename>buildenv.pl</filename> file, and add a variable for the
location of the root directory, for example:
<screen>
$ENV{DOCROOT}='c:\docbook';
</screen>
<programlisting>
$ENV{DOCROOT}='c:\docbook';
</programlisting>
To build the documentation, run the command
<filename>builddoc.bat</filename>. Note that this will actually run the
build twice, in order to generate the indexes. The generated HTML files

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/intagg.sgml,v 1.4 2008/11/14 19:58:45 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/intagg.sgml,v 1.5 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="intagg">
<title>intagg</title>
@ -44,24 +44,20 @@
<para>
Many database systems have the notion of a one to many table. Such a table
usually sits between two indexed tables, for example:
</para>
<programlisting>
<programlisting>
CREATE TABLE left (id INT PRIMARY KEY, ...);
CREATE TABLE right (id INT PRIMARY KEY, ...);
CREATE TABLE one_to_many(left INT REFERENCES left, right INT REFERENCES right);
</programlisting>
</programlisting>
<para>
It is typically used like this:
</para>
<programlisting>
SELECT right.* from right JOIN one_to_many ON (right.id = one_to_many.right)
WHERE one_to_many.left = <replaceable>item</>;
</programlisting>
<programlisting>
SELECT right.* from right JOIN one_to_many ON (right.id = one_to_many.right)
WHERE one_to_many.left = <replaceable>item</>;
</programlisting>
<para>
This will return all the items in the right hand table for an entry
in the left hand table. This is a very common construct in SQL.
</para>
@ -74,35 +70,29 @@ CREATE TABLE one_to_many(left INT REFERENCES left, right INT REFERENCES right);
left hand entry. If you have a very dynamic system, there is not much you
can do. However, if you have some data which is fairly static, you can
create a summary table with the aggregator.
</para>
<programlisting>
CREATE TABLE summary as
<programlisting>
CREATE TABLE summary AS
SELECT left, int_array_aggregate(right) AS right
FROM one_to_many
GROUP BY left;
</programlisting>
</programlisting>
<para>
This will create a table with one row per left item, and an array
of right items. Now this is pretty useless without some way of using
the array; that's why there is an array enumerator. You can do
</para>
<programlisting>
<programlisting>
SELECT left, int_array_enum(right) FROM summary WHERE left = <replaceable>item</>;
</programlisting>
</programlisting>
<para>
The above query using <function>int_array_enum</> produces the same results
as
</para>
<programlisting>
<programlisting>
SELECT left, right FROM one_to_many WHERE left = <replaceable>item</>;
</programlisting>
</programlisting>
<para>
The difference is that the query against the summary table has to get
only one row from the table, whereas the direct query against
<structname>one_to_many</> must index scan and fetch a row for each entry.
@ -112,9 +102,8 @@ SELECT left, right FROM one_to_many WHERE left = <replaceable>item</>;
On one system, an <command>EXPLAIN</> showed a query with a cost of 8488 was
reduced to a cost of 329. The original query was a join involving the
<structname>one_to_many</> table, which was replaced by:
</para>
<programlisting>
<programlisting>
SELECT right, count(right) FROM
( SELECT left, int_array_enum(right) AS right
FROM summary JOIN (SELECT left FROM left_table WHERE left = <replaceable>item</>) AS lefts
@ -122,7 +111,8 @@ SELECT right, count(right) FROM
) AS list
GROUP BY right
ORDER BY count DESC;
</programlisting>
</programlisting>
</para>
</sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/intarray.sgml,v 1.10 2010/05/05 15:10:25 heikki Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/intarray.sgml,v 1.11 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="intarray">
<title>intarray</title>
@ -271,7 +271,7 @@
<sect2>
<title>Example</title>
<programlisting>
<programlisting>
-- a message can be in one or more <quote>sections</>
CREATE TABLE message (mid INT PRIMARY KEY, sections INT[], ...);
@ -286,7 +286,7 @@ SELECT message.mid FROM message WHERE message.sections @&gt; '{1,2}';
-- the same, using QUERY operator
SELECT message.mid FROM message WHERE message.sections @@ '1&amp;2'::query_int;
</programlisting>
</programlisting>
</sect2>
<sect2>
@ -297,13 +297,13 @@ SELECT message.mid FROM message WHERE message.sections @@ '1&amp;2'::query_int;
benchmark test suite. To run:
</para>
<programlisting>
cd .../bench
createdb TEST
psql TEST &lt; ../_int.sql
./create_test.pl | psql TEST
./bench.pl
</programlisting>
<programlisting>
cd .../bench
createdb TEST
psql TEST &lt; ../_int.sql
./create_test.pl | psql TEST
./bench.pl
</programlisting>
<para>
The <filename>bench.pl</> script has numerous options, which

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/isn.sgml,v 1.5 2009/05/18 11:08:24 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/isn.sgml,v 1.6 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="isn">
<title>isn</title>
@ -295,7 +295,7 @@
<sect2>
<title>Examples</title>
<programlisting>
<programlisting>
--Using the types directly:
SELECT isbn('978-0-393-04002-9');
SELECT isbn13('0901690546');
@ -333,7 +333,7 @@ UPDATE test SET id = make_valid(id) WHERE id = '2-205-00876-X!';
SELECT * FROM test;
SELECT isbn13(id) FROM test;
</programlisting>
</programlisting>
</sect2>
<sect2>
@ -342,24 +342,20 @@ SELECT isbn13(id) FROM test;
<para>
The information to implement this module was collected from
several sites, including:
</para>
<programlisting>
http://www.isbn-international.org/
http://www.issn.org/
http://www.ismn-international.org/
http://www.wikipedia.org/
</programlisting>
<itemizedlist>
<listitem><para><ulink url="http://www.isbn-international.org/"></ulink></para></listitem>
<listitem><para><ulink url="http://www.issn.org/"></ulink></para></listitem>
<listitem><para><ulink url="http://www.ismn-international.org/"></ulink></para></listitem>
<listitem><para><ulink url="http://www.wikipedia.org/"></ulink></para></listitem>
</itemizedlist>
<para>
The prefixes used for hyphenation were also compiled from:
</para>
<programlisting>
http://www.gs1.org/productssolutions/idkeys/support/prefix_list.html
http://www.isbn-international.org/en/identifiers.html
http://www.ismn-international.org/ranges.html
</programlisting>
<itemizedlist>
<listitem><para><ulink url="http://www.gs1.org/productssolutions/idkeys/support/prefix_list.html"></ulink></para></listitem>
<listitem><para><ulink url="http://www.isbn-international.org/en/identifiers.html"></ulink></para></listitem>
<listitem><para><ulink url="http://www.ismn-international.org/ranges.html"></ulink></para></listitem>
</itemizedlist>
<para>
Care was taken during the creation of the algorithms and they
were meticulously verified against the suggested algorithms
in the official ISBN, ISMN, ISSN User Manuals.

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/lo.sgml,v 1.3 2007/12/06 04:12:10 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/lo.sgml,v 1.4 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="lo">
<title>lo</title>
@ -66,12 +66,12 @@
Here's a simple example of usage:
</para>
<programlisting>
CREATE TABLE image (title TEXT, raster lo);
<programlisting>
CREATE TABLE image (title TEXT, raster lo);
CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster);
</programlisting>
CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster);
</programlisting>
<para>
For each column that will contain unique references to large objects,

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/ltree.sgml,v 1.4 2010/03/17 17:12:31 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ltree.sgml,v 1.5 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="ltree">
<title>ltree</title>
@ -58,32 +58,32 @@
for matching <type>ltree</> values. A simple word matches that
label within a path. A star symbol (<literal>*</>) matches zero
or more labels. For example:
<programlisting>
<synopsis>
foo <lineannotation>Match the exact label path <literal>foo</></lineannotation>
*.foo.* <lineannotation>Match any label path containing the label <literal>foo</></lineannotation>
*.foo <lineannotation>Match any label path whose last label is <literal>foo</></lineannotation>
</programlisting>
</synopsis>
</para>
<para>
Star symbols can also be quantified to restrict how many labels
they can match:
<programlisting>
<synopsis>
*{<replaceable>n</>} <lineannotation>Match exactly <replaceable>n</> labels</lineannotation>
*{<replaceable>n</>,} <lineannotation>Match at least <replaceable>n</> labels</lineannotation>
*{<replaceable>n</>,<replaceable>m</>} <lineannotation>Match at least <replaceable>n</> but not more than <replaceable>m</> labels</lineannotation>
*{,<replaceable>m</>} <lineannotation>Match at most <replaceable>m</> labels &mdash; same as </lineannotation> *{0,<replaceable>m</>}
</programlisting>
</synopsis>
</para>
<para>
There are several modifiers that can be put at the end of a non-star
label in <type>lquery</> to make it match more than just the exact match:
<programlisting>
<synopsis>
@ <lineannotation>Match case-insensitively, for example <literal>a@</> matches <literal>A</></lineannotation>
* <lineannotation>Match any label with this prefix, for example <literal>foo*</> matches <literal>foobar</></lineannotation>
% <lineannotation>Match initial underscore-separated words</lineannotation>
</programlisting>
</synopsis>
The behavior of <literal>%</> is a bit complicated. It tries to match
words rather than the entire label. For example
<literal>foo_bar%</> matches <literal>foo_bar_baz</> but not
@ -102,10 +102,10 @@ foo <lineannotation>Match the exact label path <literal>foo</></lineanno
<para>
Here's an annotated example of <type>lquery</type>:
<programlisting>
Top.*{0,2}.sport*@.!football|tennis.Russ*|Spain
a. b. c. d. e.
</programlisting>
<programlisting>
Top.*{0,2}.sport*@.!football|tennis.Russ*|Spain
a. b. c. d. e.
</programlisting>
This query will match any label path that:
</para>
<orderedlist numeration='loweralpha'>
@ -154,9 +154,9 @@ foo <lineannotation>Match the exact label path <literal>foo</></lineanno
<para>
Here's an example <type>ltxtquery</type>:
<programlisting>
Europe &amp; Russia*@ &amp; !Transportation
</programlisting>
<programlisting>
Europe &amp; Russia*@ &amp; !Transportation
</programlisting>
This will match paths that contain the label <literal>Europe</literal> and
any label beginning with <literal>Russia</literal> (case-insensitive),
but not paths containing the label <literal>Transportation</literal>.
@ -504,9 +504,9 @@ foo <lineannotation>Match the exact label path <literal>foo</></lineanno
<para>
Example of creating such an index:
</para>
<programlisting>
CREATE INDEX path_gist_idx ON test USING GIST (path);
</programlisting>
<programlisting>
CREATE INDEX path_gist_idx ON test USING GIST (path);
</programlisting>
</listitem>
<listitem>
<para>
@ -517,9 +517,9 @@ foo <lineannotation>Match the exact label path <literal>foo</></lineanno
<para>
Example of creating such an index:
</para>
<programlisting>
CREATE INDEX path_gist_idx ON test USING GIST (array_path);
</programlisting>
<programlisting>
CREATE INDEX path_gist_idx ON test USING GIST (array_path);
</programlisting>
<para>
Note: This index type is lossy.
</para>
@ -535,7 +535,7 @@ foo <lineannotation>Match the exact label path <literal>foo</></lineanno
<filename>contrib/ltree/ltreetest.sql</> in the source distribution):
</para>
<programlisting>
<programlisting>
CREATE TABLE test (path ltree);
INSERT INTO test VALUES ('Top');
INSERT INTO test VALUES ('Top.Science');
@ -552,31 +552,29 @@ INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Galaxies');
INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Astronauts');
CREATE INDEX path_gist_idx ON test USING gist(path);
CREATE INDEX path_idx ON test USING btree(path);
</programlisting>
</programlisting>
<para>
Now, we have a table <structname>test</> populated with data describing
the hierarchy shown below:
</para>
<programlisting>
Top
/ | \
Science Hobbies Collections
/ | \
Astronomy Amateurs_Astronomy Pictures
/ \ |
Astrophysics Cosmology Astronomy
/ | \
Galaxies Stars Astronauts
</programlisting>
<literallayout class="monospaced">
Top
/ | \
Science Hobbies Collections
/ | \
Astronomy Amateurs_Astronomy Pictures
/ \ |
Astrophysics Cosmology Astronomy
/ | \
Galaxies Stars Astronauts
</literallayout>
<para>
We can do inheritance:
</para>
<programlisting>
ltreetest=# select path from test where path &lt;@ 'Top.Science';
<screen>
ltreetest=&gt; SELECT path FROM test WHERE path &lt;@ 'Top.Science';
path
------------------------------------
Top.Science
@ -584,14 +582,13 @@ ltreetest=# select path from test where path &lt;@ 'Top.Science';
Top.Science.Astronomy.Astrophysics
Top.Science.Astronomy.Cosmology
(4 rows)
</programlisting>
</screen>
</para>
<para>
Here are some examples of path matching:
</para>
<programlisting>
ltreetest=# select path from test where path ~ '*.Astronomy.*';
<screen>
ltreetest=&gt; SELECT path FROM test WHERE path ~ '*.Astronomy.*';
path
-----------------------------------------------
Top.Science.Astronomy
@ -603,20 +600,20 @@ ltreetest=# select path from test where path ~ '*.Astronomy.*';
Top.Collections.Pictures.Astronomy.Astronauts
(7 rows)
ltreetest=# select path from test where path ~ '*.!pictures@.*.Astronomy.*';
ltreetest=&gt; SELECT path FROM test WHERE path ~ '*.!pictures@.*.Astronomy.*';
path
------------------------------------
Top.Science.Astronomy
Top.Science.Astronomy.Astrophysics
Top.Science.Astronomy.Cosmology
(3 rows)
</programlisting>
</screen>
</para>
<para>
Here are some examples of full text search:
</para>
<programlisting>
ltreetest=# select path from test where path @ 'Astro*% &amp; !pictures@';
<screen>
ltreetest=&gt; SELECT path FROM test WHERE path @ 'Astro*% &amp; !pictures@';
path
------------------------------------
Top.Science.Astronomy
@ -625,45 +622,46 @@ ltreetest=# select path from test where path @ 'Astro*% &amp; !pictures@';
Top.Hobbies.Amateurs_Astronomy
(4 rows)
ltreetest=# select path from test where path @ 'Astro* &amp; !pictures@';
ltreetest=&gt; SELECT path FROM test WHERE path @ 'Astro* &amp; !pictures@';
path
------------------------------------
Top.Science.Astronomy
Top.Science.Astronomy.Astrophysics
Top.Science.Astronomy.Cosmology
(3 rows)
</programlisting>
</screen>
</para>
<para>
Path construction using functions:
</para>
<programlisting>
ltreetest=# select subpath(path,0,2)||'Space'||subpath(path,2) from test where path &lt;@ 'Top.Science.Astronomy';
<screen>
ltreetest=&gt; SELECT subpath(path,0,2)||'Space'||subpath(path,2) FROM test WHERE path &lt;@ 'Top.Science.Astronomy';
?column?
------------------------------------------
Top.Science.Space.Astronomy
Top.Science.Space.Astronomy.Astrophysics
Top.Science.Space.Astronomy.Cosmology
(3 rows)
</programlisting>
</screen>
</para>
<para>
We could simplify this by creating a SQL function that inserts a label
at a specified position in a path:
</para>
<programlisting>
<screen>
CREATE FUNCTION ins_label(ltree, int, text) RETURNS ltree
AS 'select subpath($1,0,$2) || $3 || subpath($1,$2);'
LANGUAGE SQL IMMUTABLE;
AS 'select subpath($1,0,$2) || $3 || subpath($1,$2);'
LANGUAGE SQL IMMUTABLE;
ltreetest=# select ins_label(path,2,'Space') from test where path &lt;@ 'Top.Science.Astronomy';
ltreetest=&gt; SELECT ins_label(path,2,'Space') FROM test WHERE path &lt;@ 'Top.Science.Astronomy';
ins_label
------------------------------------------
Top.Science.Space.Astronomy
Top.Science.Space.Astronomy.Astrophysics
Top.Science.Space.Astronomy.Cosmology
(3 rows)
</programlisting>
</screen>
</para>
</sect2>
<sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.80 2010/04/26 19:56:55 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.81 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="monitoring">
<title>Monitoring Database Activity</title>
@ -1680,7 +1680,7 @@ Total time (ns) 2312105013
<para>
Add the probe definition to <filename>src/backend/utils/probes.d</>:
<programlisting>
probe transaction__start(LocalTransactionId);
probe transaction__start(LocalTransactionId);
</programlisting>
Note the use of the double underline in the probe name. In a DTrace
script using the probe, the double underline needs to be replaced with a
@ -1698,7 +1698,7 @@ Total time (ns) 2312105013
in the source code. In this case, it looks like the following:
<programlisting>
TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
</programlisting>
</para>
</step>
@ -1748,8 +1748,8 @@ Total time (ns) 2312105013
is actually enabled:
<programlisting>
if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
</programlisting>
Each trace macro has a corresponding <literal>ENABLED</> macro.

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/oid2name.sgml,v 1.8 2010/05/25 15:55:28 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/oid2name.sgml,v 1.9 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="oid2name">
<title>oid2name</title>
@ -147,7 +147,7 @@
<sect2>
<title>Examples</title>
<programlisting>
<screen>
$ # what's in this database server, anyway?
$ oid2name
All databases:
@ -264,7 +264,7 @@ From database "alvherre":
Filenode Table Name
----------------------
155156 foo
</programlisting>
</screen>
</sect2>
<sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pageinspect.sgml,v 1.6 2009/06/08 16:22:44 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pageinspect.sgml,v 1.7 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pageinspect">
<title>pageinspect</title>
@ -62,15 +62,12 @@
<para>
A page image obtained with <function>get_raw_page</function> should be
passed as argument. For example:
</para>
<programlisting>
<screen>
test=# SELECT * FROM page_header(get_raw_page('pg_class', 0));
lsn | tli | flags | lower | upper | special | pagesize | version | prune_xid
-----------+-----+-------+-------+-------+---------+----------+---------+-----------
0/24A1B50 | 1 | 1 | 232 | 368 | 8192 | 8192 | 4 | 0
</programlisting>
<para>
</screen>
The returned columns correspond to the fields in the
<structname>PageHeaderData</> struct.
See <filename>src/include/storage/bufpage.h</> for details.
@ -93,11 +90,9 @@ test=# SELECT * FROM page_header(get_raw_page('pg_class', 0));
<para>
A heap page image obtained with <function>get_raw_page</function> should
be passed as argument. For example:
</para>
<programlisting>
<screen>
test=# SELECT * FROM heap_page_items(get_raw_page('pg_class', 0));
</programlisting>
<para>
</screen>
See <filename>src/include/storage/itemid.h</> and
<filename>src/include/access/htup.h</> for explanations of the fields
returned.
@ -114,8 +109,7 @@ test=# SELECT * FROM heap_page_items(get_raw_page('pg_class', 0));
<para>
<function>bt_metap</function> returns information about a btree
index's metapage. For example:
</para>
<programlisting>
<screen>
test=# SELECT * FROM bt_metap('pg_cast_oid_index');
-[ RECORD 1 ]-----
magic | 340322
@ -124,7 +118,8 @@ root | 1
level | 0
fastroot | 1
fastlevel | 0
</programlisting>
</screen>
</para>
</listitem>
</varlistentry>
@ -137,8 +132,7 @@ fastlevel | 0
<para>
<function>bt_page_stats</function> returns summary information about
single pages of btree indexes. For example:
</para>
<programlisting>
<screen>
test=# SELECT * FROM bt_page_stats('pg_cast_oid_index', 1);
-[ RECORD 1 ]-+-----
blkno | 1
@ -152,7 +146,8 @@ btpo_prev | 0
btpo_next | 0
btpo | 0
btpo_flags | 3
</programlisting>
</screen>
</para>
</listitem>
</varlistentry>
@ -165,8 +160,7 @@ btpo_flags | 3
<para>
<function>bt_page_items</function> returns detailed information about
all of the items on a btree index page. For example:
</para>
<programlisting>
<screen>
test=# SELECT * FROM bt_page_items('pg_cast_oid_index', 1);
itemoffset | ctid | itemlen | nulls | vars | data
------------+---------+---------+-------+------+-------------
@ -178,7 +172,8 @@ test=# SELECT * FROM bt_page_items('pg_cast_oid_index', 1);
6 | (0,6) | 12 | f | f | 28 27 00 00
7 | (0,7) | 12 | f | f | 29 27 00 00
8 | (0,8) | 12 | f | f | 2a 27 00 00
</programlisting>
</screen>
</para>
</listitem>
</varlistentry>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgarchivecleanup.sgml,v 1.1 2010/06/14 17:25:24 sriggs Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgarchivecleanup.sgml,v 1.2 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgarchivecleanup">
<title>pg_archivecleanup</title>
@ -38,11 +38,9 @@
To configure a standby
server to use <application>pg_archivecleanup</>, put this into its
<filename>recovery.conf</filename> configuration file:
</para>
<programlisting>
<programlisting>
archive_cleanup_command = 'pg_archivecleanup <replaceable>archiveDir</> %r'
</programlisting>
<para>
</programlisting>
where <replaceable>archiveDir</> is the directory from which WAL segment
files should be restored.
</para>
@ -58,11 +56,9 @@ archive_cleanup_command = 'pg_archivecleanup <replaceable>archiveDir</> %r'
</para>
<para>
The full syntax of <application>pg_archivecleanup</>'s command line is
</para>
<synopsis>
<synopsis>
pg_archivecleanup <optional> <replaceable>option</> ... </optional> <replaceable>archivelocation</> <replaceable>restartwalfile</>
</synopsis>
<para>
</synopsis>
When used as a standalone program all WAL files logically preceding the
<literal>restartwalfile</> will be removed <replaceable>archivelocation</>.
In this mode, if you specify a .backup filename, then only the file prefix
@ -70,15 +66,13 @@ pg_archivecleanup <optional> <replaceable>option</> ... </optional> <replaceable
all WAL files archived prior to a specific base backup without error.
For example, the following example will remove all files older than
WAL filename 000000010000003700000010:
</para>
<programlisting>
<programlisting>
pg_archivecleanup -d archive 000000010000003700000010.00000020.backup
pg_archivecleanup: keep WAL files 000000010000003700000010 and later
pg_archivecleanup: removing "archive/00000001000000370000000F"
pg_archivecleanup: removing "archive/00000001000000370000000E"
</programlisting>
<para>
</programlisting>
<application>pg_archivecleanup</application> assumes that
<replaceable>archivelocation</> is a directory readable and writable by the
server-owning user.
@ -110,12 +104,10 @@ pg_archivecleanup: removing "archive/00000001000000370000000E"
<sect2>
<title>Examples</title>
<para>On Linux or Unix systems, you might use:</para>
<programlisting>
<para>On Linux or Unix systems, you might use:
<programlisting>
archive_cleanup_command = 'pg_archivecleanup -d .../archive %r 2>>cleanup.log'
</programlisting>
<para>
</programlisting>
where the archive directory is physically located on the standby server,
so that the <literal>archive_command</> is accessing it across NFS,
but the files are local to the standby.

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgbench.sgml,v 1.16 2010/05/25 15:55:28 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgbench.sgml,v 1.17 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgbench">
<title>pgbench</title>
@ -22,7 +22,7 @@
<para>
Typical output from pgbench looks like:
<programlisting>
<screen>
transaction type: TPC-B (sort of)
scaling factor: 10
query mode: simple
@ -32,7 +32,7 @@ number of transactions per client: 1000
number of transactions actually processed: 10000/10000
tps = 85.184871 (including connections establishing)
tps = 85.296346 (excluding connections establishing)
</programlisting>
</screen>
The first six lines report some of the most important parameter
settings. The next line reports the number of transactions completed
@ -53,9 +53,9 @@ tps = 85.296346 (excluding connections establishing)
step, but will instead need to do whatever setup your test needs.)
Initialization looks like:
<programlisting>
<programlisting>
pgbench -i <optional> <replaceable>other-options</> </optional> <replaceable>dbname</>
</programlisting>
</programlisting>
where <replaceable>dbname</> is the name of the already-created
database to test in. (You may also need <literal>-h</>,
@ -77,16 +77,14 @@ pgbench -i <optional> <replaceable>other-options</> </optional> <replaceable>dbn
<para>
At the default <quote>scale factor</> of 1, the tables initially
contain this many rows:
</para>
<programlisting>
<screen>
table # of rows
---------------------------------
pgbench_branches 1
pgbench_tellers 10
pgbench_accounts 100000
pgbench_history 0
</programlisting>
<para>
</screen>
You can (and, for most purposes, probably should) increase the number
of rows by using the <literal>-s</> (scale factor) option. The
<literal>-F</> (fillfactor) option might also be used at this point.
@ -96,9 +94,9 @@ pgbench_history 0
Once you have done the necessary setup, you can run your benchmark
with a command that doesn't include <literal>-i</>, that is
<programlisting>
<programlisting>
pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
</programlisting>
</programlisting>
In nearly all cases, you'll need some options to make a useful test.
The most important options are <literal>-c</> (number of clients),
@ -478,9 +476,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
<para>
Example:
<programlisting>
<programlisting>
\set ntellers 10 * :scale
</programlisting>
</programlisting>
</para>
</listitem>
</varlistentry>
@ -501,9 +499,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
<para>
Example:
<programlisting>
<programlisting>
\setrandom aid 1 :naccounts
</programlisting>
</programlisting>
</para>
</listitem>
</varlistentry>
@ -525,9 +523,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
<para>
Example:
<programlisting>
<programlisting>
\sleep 10 ms
</programlisting>
</programlisting>
</para>
</listitem>
</varlistentry>
@ -554,9 +552,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
<para>
Example:
<programlisting>
<programlisting>
\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon
</programlisting>
</programlisting>
</para>
</listitem>
</varlistentry>
@ -573,9 +571,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
<para>
Example:
<programlisting>
<programlisting>
\shell command literal_argument :variable ::literal_starting_with_colon
</programlisting>
</programlisting>
</para>
</listitem>
</varlistentry>
@ -585,7 +583,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
As an example, the full definition of the built-in TPC-B-like
transaction is:
<programlisting>
<programlisting>
\set nbranches :scale
\set ntellers 10 * :scale
\set naccounts 100000 * :scale
@ -600,7 +598,7 @@ UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;
</programlisting>
</programlisting>
This script allows each iteration of the transaction to reference
different, randomly-chosen rows. (This example also shows why it's
@ -630,9 +628,9 @@ END;
<para>
The format of the log is:
<programlisting>
<replaceable>client_id</> <replaceable>transaction_no</> <replaceable>time</> <replaceable>file_no</> <replaceable>time_epoch</> <replaceable>time_us</>
</programlisting>
<synopsis>
<replaceable>client_id</> <replaceable>transaction_no</> <replaceable>time</> <replaceable>file_no</> <replaceable>time_epoch</> <replaceable>time_us</>
</synopsis>
where <replaceable>time</> is the elapsed transaction time in microseconds,
<replaceable>file_no</> identifies which script file was used
@ -646,12 +644,12 @@ END;
<para>
Here are example outputs:
<programlisting>
<screen>
0 199 2241 0 1175850568 995598
0 200 2465 0 1175850568 998079
0 201 2513 0 1175850569 608
0 202 2038 0 1175850569 2663
</programlisting>
</screen>
</para>
</sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgbuffercache.sgml,v 2.6 2010/02/07 20:48:09 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgbuffercache.sgml,v 2.7 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgbuffercache">
<title>pg_buffercache</title>
@ -134,29 +134,30 @@
<sect2>
<title>Sample output</title>
<programlisting>
regression=# SELECT c.relname, count(*) AS buffers
FROM pg_buffercache b INNER JOIN pg_class c
ON b.relfilenode = pg_relation_filenode(c.oid) AND
b.reldatabase IN (0, (SELECT oid FROM pg_database
WHERE datname = current_database()))
GROUP BY c.relname
ORDER BY 2 DESC
LIMIT 10;
relname | buffers
---------------------------------+---------
tenk2 | 345
tenk1 | 141
pg_proc | 46
pg_class | 45
pg_attribute | 43
pg_class_relname_nsp_index | 30
pg_proc_proname_args_nsp_index | 28
pg_attribute_relid_attnam_index | 26
pg_depend | 22
pg_depend_reference_index | 20
(10 rows)
</programlisting>
<screen>
regression=# SELECT c.relname, count(*) AS buffers
FROM pg_buffercache b INNER JOIN pg_class c
ON b.relfilenode = pg_relation_filenode(c.oid) AND
b.reldatabase IN (0, (SELECT oid FROM pg_database
WHERE datname = current_database()))
GROUP BY c.relname
ORDER BY 2 DESC
LIMIT 10;
relname | buffers
---------------------------------+---------
tenk2 | 345
tenk1 | 141
pg_proc | 46
pg_class | 45
pg_attribute | 43
pg_class_relname_nsp_index | 30
pg_proc_proname_args_nsp_index | 28
pg_attribute_relid_attnam_index | 26
pg_depend | 22
pg_depend_reference_index | 20
(10 rows)
</screen>
</sect2>
<sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgcrypto.sgml,v 1.9 2010/06/29 22:29:14 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgcrypto.sgml,v 1.10 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgcrypto">
<title>pgcrypto</title>
@ -18,10 +18,10 @@
<sect3>
<title><function>digest()</function></title>
<synopsis>
digest(data text, type text) returns bytea
digest(data bytea, type text) returns bytea
</synopsis>
<synopsis>
digest(data text, type text) returns bytea
digest(data bytea, type text) returns bytea
</synopsis>
<para>
Computes a binary hash of the given <parameter>data</>.
@ -37,21 +37,21 @@
<para>
If you want the digest as a hexadecimal string, use
<function>encode()</> on the result. For example:
<programlisting>
CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$
SELECT encode(digest($1, 'sha1'), 'hex')
$$ LANGUAGE SQL STRICT IMMUTABLE;
</programlisting>
</para>
<programlisting>
CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$
SELECT encode(digest($1, 'sha1'), 'hex')
$$ LANGUAGE SQL STRICT IMMUTABLE;
</programlisting>
</sect3>
<sect3>
<title><function>hmac()</function></title>
<synopsis>
hmac(data text, key text, type text) returns bytea
hmac(data bytea, key text, type text) returns bytea
</synopsis>
<synopsis>
hmac(data text, key text, type text) returns bytea
hmac(data bytea, key text, type text) returns bytea
</synopsis>
<para>
Calculates hashed MAC for <parameter>data</> with key <parameter>key</>.
@ -163,9 +163,9 @@
<sect3>
<title><function>crypt()</></title>
<synopsis>
crypt(password text, salt text) returns text
</synopsis>
<synopsis>
crypt(password text, salt text) returns text
</synopsis>
<para>
Calculates a crypt(3)-style hash of <parameter>password</>.
@ -176,17 +176,15 @@
</para>
<para>
Example of setting a new password:
<programlisting>
UPDATE ... SET pswhash = crypt('new password', gen_salt('md5'));
</programlisting>
</para>
<programlisting>
UPDATE ... SET pswhash = crypt('new password', gen_salt('md5'));
</programlisting>
<para>
Example of authentication:
</para>
<programlisting>
SELECT pswhash = crypt('entered password', pswhash) FROM ... ;
</programlisting>
<para>
<programlisting>
SELECT pswhash = crypt('entered password', pswhash) FROM ... ;
</programlisting>
This returns <literal>true</> if the entered password is correct.
</para>
</sect3>
@ -194,9 +192,9 @@
<sect3>
<title><function>gen_salt()</></title>
<synopsis>
gen_salt(type text [, iter_count integer ]) returns text
</synopsis>
<synopsis>
gen_salt(type text [, iter_count integer ]) returns text
</synopsis>
<para>
Generates a new random salt string for use in <function>crypt()</>.
@ -489,10 +487,10 @@
<sect3>
<title><function>pgp_sym_encrypt()</function></title>
<synopsis>
pgp_sym_encrypt(data text, psw text [, options text ]) returns bytea
pgp_sym_encrypt_bytea(data bytea, psw text [, options text ]) returns bytea
</synopsis>
<synopsis>
pgp_sym_encrypt(data text, psw text [, options text ]) returns bytea
pgp_sym_encrypt_bytea(data bytea, psw text [, options text ]) returns bytea
</synopsis>
<para>
Encrypt <parameter>data</> with a symmetric PGP key <parameter>psw</>.
The <parameter>options</> parameter can contain option settings,
@ -503,10 +501,10 @@
<sect3>
<title><function>pgp_sym_decrypt()</function></title>
<synopsis>
pgp_sym_decrypt(msg bytea, psw text [, options text ]) returns text
pgp_sym_decrypt_bytea(msg bytea, psw text [, options text ]) returns bytea
</synopsis>
<synopsis>
pgp_sym_decrypt(msg bytea, psw text [, options text ]) returns text
pgp_sym_decrypt_bytea(msg bytea, psw text [, options text ]) returns bytea
</synopsis>
<para>
Decrypt a symmetric-key-encrypted PGP message.
</para>
@ -524,10 +522,10 @@
<sect3>
<title><function>pgp_pub_encrypt()</function></title>
<synopsis>
pgp_pub_encrypt(data text, key bytea [, options text ]) returns bytea
pgp_pub_encrypt_bytea(data bytea, key bytea [, options text ]) returns bytea
</synopsis>
<synopsis>
pgp_pub_encrypt(data text, key bytea [, options text ]) returns bytea
pgp_pub_encrypt_bytea(data bytea, key bytea [, options text ]) returns bytea
</synopsis>
<para>
Encrypt <parameter>data</> with a public PGP key <parameter>key</>.
Giving this function a secret key will produce a error.
@ -541,10 +539,10 @@
<sect3>
<title><function>pgp_pub_decrypt()</function></title>
<synopsis>
pgp_pub_decrypt(msg bytea, key bytea [, psw text [, options text ]]) returns text
pgp_pub_decrypt_bytea(msg bytea, key bytea [, psw text [, options text ]]) returns bytea
</synopsis>
<synopsis>
pgp_pub_decrypt(msg bytea, key bytea [, psw text [, options text ]]) returns text
pgp_pub_decrypt_bytea(msg bytea, key bytea [, psw text [, options text ]]) returns bytea
</synopsis>
<para>
Decrypt a public-key-encrypted message. <parameter>key</> must be the
secret key corresponding to the public key that was used to encrypt.
@ -566,9 +564,9 @@
<sect3>
<title><function>pgp_key_id()</function></title>
<synopsis>
pgp_key_id(bytea) returns text
</synopsis>
<synopsis>
pgp_key_id(bytea) returns text
</synopsis>
<para>
<function>pgp_key_id</> extracts the key ID of a PGP public or secret key.
Or it gives the key ID that was used for encrypting the data, if given
@ -608,10 +606,10 @@
<sect3>
<title><function>armor()</function>, <function>dearmor()</function></title>
<synopsis>
armor(data bytea) returns text
dearmor(data text) returns bytea
</synopsis>
<synopsis>
armor(data bytea) returns text
dearmor(data text) returns bytea
</synopsis>
<para>
These functions wrap/unwrap binary data into PGP Ascii Armor format,
which is basically Base64 with CRC and additional formatting.
@ -625,10 +623,10 @@
Options are named to be similar to GnuPG. An option's value should be
given after an equal sign; separate options from each other with commas.
For example:
<programlisting>
pgp_sym_encrypt(data, psw, 'compress-algo=1, cipher-algo=aes256')
</programlisting>
</para>
<programlisting>
pgp_sym_encrypt(data, psw, 'compress-algo=1, cipher-algo=aes256')
</programlisting>
<para>
All of the options except <literal>convert-crlf</literal> apply only to
@ -648,11 +646,11 @@
<para>
Which cipher algorithm to use.
</para>
<programlisting>
Values: bf, aes128, aes192, aes256 (OpenSSL-only: <literal>3des</literal>, <literal>cast5</literal>)
Default: aes128
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</programlisting>
<literallayout>
Values: bf, aes128, aes192, aes256 (OpenSSL-only: <literal>3des</literal>, <literal>cast5</literal>)
Default: aes128
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</literallayout>
</sect4>
<sect4>
@ -662,14 +660,14 @@
Which compression algorithm to use. Only available if
<productname>PostgreSQL</productname> was built with zlib.
</para>
<programlisting>
Values:
0 - no compression
1 - ZIP compression
2 - ZLIB compression (= ZIP plus meta-data and block CRCs)
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</programlisting>
<literallayout>
Values:
0 - no compression
1 - ZIP compression
2 - ZLIB compression (= ZIP plus meta-data and block CRCs)
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</literallayout>
</sect4>
<sect4>
@ -679,11 +677,11 @@
How much to compress. Higher levels compress smaller but are slower.
0 disables compression.
</para>
<programlisting>
Values: 0, 1-9
Default: 6
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</programlisting>
<literallayout>
Values: 0, 1-9
Default: 6
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</literallayout>
</sect4>
<sect4>
@ -696,11 +694,11 @@
<literal>\r\n</literal> line-feeds. Use this to get fully RFC-compliant
behavior.
</para>
<programlisting>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt, pgp_sym_decrypt, pgp_pub_decrypt
</programlisting>
<literallayout>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt, pgp_sym_decrypt, pgp_pub_decrypt
</literallayout>
</sect4>
<sect4>
@ -712,11 +710,11 @@
the addition of SHA-1 protected packets to RFC 4880.
Recent gnupg.org and pgp.com software supports it fine.
</para>
<programlisting>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</programlisting>
<literallayout>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</literallayout>
</sect4>
<sect4>
@ -727,11 +725,11 @@
session key; this is for symmetric-key encryption, which by default
uses the S2K key directly.
</para>
<programlisting>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt
</programlisting>
<literallayout>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt
</literallayout>
</sect4>
<sect4>
@ -740,14 +738,14 @@
<para>
Which S2K algorithm to use.
</para>
<programlisting>
Values:
0 - Without salt. Dangerous!
1 - With salt but with fixed iteration count.
3 - Variable iteration count.
Default: 3
Applies to: pgp_sym_encrypt
</programlisting>
<literallayout>
Values:
0 - Without salt. Dangerous!
1 - With salt but with fixed iteration count.
3 - Variable iteration count.
Default: 3
Applies to: pgp_sym_encrypt
</literallayout>
</sect4>
<sect4>
@ -756,11 +754,11 @@
<para>
Which digest algorithm to use in S2K calculation.
</para>
<programlisting>
Values: md5, sha1
Default: sha1
Applies to: pgp_sym_encrypt
</programlisting>
<literallayout>
Values: md5, sha1
Default: sha1
Applies to: pgp_sym_encrypt
</literallayout>
</sect4>
<sect4>
@ -769,11 +767,11 @@
<para>
Which cipher to use for encrypting separate session key.
</para>
<programlisting>
Values: bf, aes, aes128, aes192, aes256
Default: use cipher-algo
Applies to: pgp_sym_encrypt
</programlisting>
<literallayout>
Values: bf, aes, aes128, aes192, aes256
Default: use cipher-algo
Applies to: pgp_sym_encrypt
</literallayout>
</sect4>
<sect4>
@ -785,11 +783,11 @@
be done, but the message will be tagged as UTF-8. Without this option
it will not be.
</para>
<programlisting>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</programlisting>
<literallayout>
Values: 0, 1
Default: 0
Applies to: pgp_sym_encrypt, pgp_pub_encrypt
</literallayout>
</sect4>
</sect3>
@ -798,10 +796,10 @@
<para>
To generate a new key:
<programlisting>
gpg --gen-key
</programlisting>
</para>
<programlisting>
gpg --gen-key
</programlisting>
<para>
The preferred key type is <quote>DSA and Elgamal</>.
</para>
@ -812,22 +810,22 @@
</para>
<para>
To list keys:
<programlisting>
gpg --list-secret-keys
</programlisting>
</para>
<programlisting>
gpg --list-secret-keys
</programlisting>
<para>
To export a public key in ascii-armor format:
<programlisting>
gpg -a --export KEYID > public.key
</programlisting>
</para>
<programlisting>
gpg -a --export KEYID > public.key
</programlisting>
<para>
To export a secret key in ascii-armor format:
<programlisting>
gpg -a --export-secret-keys KEYID > secret.key
</programlisting>
</para>
<programlisting>
gpg -a --export-secret-keys KEYID > secret.key
</programlisting>
<para>
You need to use <function>dearmor()</> on these keys before giving them to
the PGP functions. Or if you can handle binary data, you can drop
@ -905,34 +903,29 @@
encryption functions is discouraged.
</para>
<synopsis>
encrypt(data bytea, key bytea, type text) returns bytea
decrypt(data bytea, key bytea, type text) returns bytea
<synopsis>
encrypt(data bytea, key bytea, type text) returns bytea
decrypt(data bytea, key bytea, type text) returns bytea
encrypt_iv(data bytea, key bytea, iv bytea, type text) returns bytea
decrypt_iv(data bytea, key bytea, iv bytea, type text) returns bytea
</synopsis>
encrypt_iv(data bytea, key bytea, iv bytea, type text) returns bytea
decrypt_iv(data bytea, key bytea, iv bytea, type text) returns bytea
</synopsis>
<para>
Encrypt/decrypt data using the cipher method specified by
<parameter>type</parameter>. The syntax of the
<parameter>type</parameter> string is:
</para>
<synopsis>
<replaceable>algorithm</> <optional> <literal>-</> <replaceable>mode</> </optional> <optional> <literal>/pad:</> <replaceable>padding</> </optional>
</synopsis>
<para>
<synopsis>
<replaceable>algorithm</> <optional> <literal>-</> <replaceable>mode</> </optional> <optional> <literal>/pad:</> <replaceable>padding</> </optional>
</synopsis>
where <replaceable>algorithm</> is one of:
</para>
<itemizedlist>
<listitem><para><literal>bf</literal> &mdash; Blowfish</para></listitem>
<listitem><para><literal>aes</literal> &mdash; AES (Rijndael-128)</para></listitem>
</itemizedlist>
<para>
and <replaceable>mode</> is one of:
</para>
<itemizedlist>
<listitem>
<para>
@ -946,9 +939,7 @@
</para>
</listitem>
</itemizedlist>
<para>
and <replaceable>padding</> is one of:
</para>
<itemizedlist>
<listitem>
<para>
@ -961,13 +952,14 @@
</para>
</listitem>
</itemizedlist>
</para>
<para>
So, for example, these are equivalent:
<programlisting>
encrypt(data, 'fooz', 'bf')
encrypt(data, 'fooz', 'bf-cbc/pad:pkcs')
</programlisting>
</para>
<programlisting>
encrypt(data, 'fooz', 'bf')
encrypt(data, 'fooz', 'bf-cbc/pad:pkcs')
</programlisting>
<para>
In <function>encrypt_iv</> and <function>decrypt_iv</>, the
<parameter>iv</> parameter is the initial value for the CBC mode;
@ -980,9 +972,9 @@
<sect2>
<title>Random-data functions</title>
<synopsis>
gen_random_bytes(count integer) returns bytea
</synopsis>
<synopsis>
gen_random_bytes(count integer) returns bytea
</synopsis>
<para>
Returns <parameter>count</> cryptographically strong random bytes.
At most 1024 bytes can be extracted at a time. This is to avoid

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgfreespacemap.sgml,v 2.6 2010/04/23 23:21:43 rhaas Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgfreespacemap.sgml,v 2.7 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgfreespacemap">
<title>pg_freespacemap</title>
@ -75,7 +75,7 @@
<sect2>
<title>Sample output</title>
<programlisting>
<screen>
postgres=# SELECT * FROM pg_freespace('foo');
blkno | avail
-------+-------
@ -106,8 +106,7 @@ postgres=# SELECT * FROM pg_freespace('foo', 7);
--------------
1216
(1 row)
</programlisting>
</screen>
</sect2>
<sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgrowlocks.sgml,v 1.5 2009/05/18 11:08:24 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgrowlocks.sgml,v 1.6 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgrowlocks">
<title>pgrowlocks</title>
@ -101,10 +101,10 @@ pgrowlocks(text) returns setof record
rows. If you want to take a look at the row contents at the same time, you
could do something like this:
<programlisting>
<programlisting>
SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p
WHERE p.locked_row = a.ctid;
</programlisting>
</programlisting>
Be aware however that (as of <productname>PostgreSQL</> 8.3) such a
query will be very inefficient.
@ -114,7 +114,7 @@ SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p
<sect2>
<title>Sample output</title>
<programlisting>
<screen>
test=# SELECT * FROM pgrowlocks('t1');
locked_row | lock_type | locker | multi | xids | pids
------------+-----------+--------+-------+-----------+---------------
@ -123,7 +123,7 @@ test=# SELECT * FROM pgrowlocks('t1');
(0,3) | Exclusive | 804 | f | {804} | {29066}
(0,4) | Exclusive | 804 | f | {804} | {29066}
(4 rows)
</programlisting>
</screen>
</sect2>
<sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstandby.sgml,v 2.11 2010/05/25 15:55:28 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstandby.sgml,v 2.12 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgstandby">
<title>pg_standby</title>
@ -50,21 +50,17 @@
To configure a standby
server to use <application>pg_standby</>, put this into its
<filename>recovery.conf</filename> configuration file:
</para>
<programlisting>
<programlisting>
restore_command = 'pg_standby <replaceable>archiveDir</> %f %p %r'
</programlisting>
<para>
</programlisting>
where <replaceable>archiveDir</> is the directory from which WAL segment
files should be restored.
</para>
<para>
The full syntax of <application>pg_standby</>'s command line is
</para>
<synopsis>
<synopsis>
pg_standby <optional> <replaceable>option</> ... </optional> <replaceable>archivelocation</> <replaceable>nextwalfile</> <replaceable>xlogfilepath</> <optional> <replaceable>restartwalfile</> </optional>
</synopsis>
<para>
</synopsis>
When used within <literal>restore_command</literal>, the <literal>%f</> and
<literal>%p</> macros should be specified for <replaceable>nextwalfile</>
and <replaceable>xlogfilepath</> respectively, to provide the actual file
@ -235,21 +231,19 @@ pg_standby <optional> <replaceable>option</> ... </optional> <replaceable>archiv
<sect2>
<title>Examples</title>
<para>On Linux or Unix systems, you might use:</para>
<para>On Linux or Unix systems, you might use:
<programlisting>
<programlisting>
archive_command = 'cp %p .../archive/%f'
restore_command = 'pg_standby -d -s 2 -t /tmp/pgsql.trigger.5442 .../archive %f %p %r 2>>standby.log'
recovery_end_command = 'rm -f /tmp/pgsql.trigger.5442'
</programlisting>
<para>
</programlisting>
where the archive directory is physically located on the standby server,
so that the <literal>archive_command</> is accessing it across NFS,
but the files are local to the standby (enabling use of <literal>ln</>).
This will:
</para>
<itemizedlist>
<listitem>
<para>
@ -279,22 +273,21 @@ recovery_end_command = 'rm -f /tmp/pgsql.trigger.5442'
</para>
</listitem>
</itemizedlist>
</para>
<para>On Windows, you might use:</para>
<para>On Windows, you might use:
<programlisting>
<programlisting>
archive_command = 'copy %p ...\\archive\\%f'
restore_command = 'pg_standby -d -s 5 -t C:\pgsql.trigger.5442 ...\archive %f %p %r 2>>standby.log'
recovery_end_command = 'del C:\pgsql.trigger.5442'
</programlisting>
<para>
</programlisting>
Note that backslashes need to be doubled in the
<literal>archive_command</>, but <emphasis>not</emphasis> in the
<literal>restore_command</> or <literal>recovery_end_command</>.
This will:
</para>
<itemizedlist>
<listitem>
<para>
@ -329,6 +322,7 @@ recovery_end_command = 'del C:\pgsql.trigger.5442'
</para>
</listitem>
</itemizedlist>
</para>
<para>
The <literal>copy</> command on Windows sets the final file size

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstatstatements.sgml,v 1.6 2010/01/08 00:38:20 itagaki Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstatstatements.sgml,v 1.7 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgstatstatements">
<title>pg_stat_statements</title>
@ -279,22 +279,22 @@
<filename>postgresql.conf</> file,
you will need to add <literal>pg_stat_statements</> to
<xref linkend="guc-custom-variable-classes">. Typical usage might be:
</para>
<programlisting>
<programlisting>
# postgresql.conf
shared_preload_libraries = 'pg_stat_statements'
custom_variable_classes = 'pg_stat_statements'
pg_stat_statements.max = 10000
pg_stat_statements.track = all
</programlisting>
</programlisting>
</para>
</sect2>
<sect2>
<title>Sample output</title>
<programlisting>
<screen>
bench=# SELECT pg_stat_statements_reset();
$ pgbench -i bench
@ -334,7 +334,7 @@ calls | 1
total_time | 0.08142
rows | 0
hit_percent | 34.4947735191637631
</programlisting>
</screen>
</sect2>
<sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstattuple.sgml,v 1.5 2009/05/18 11:08:24 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstattuple.sgml,v 1.6 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgstattuple">
<title>pgstattuple</title>
@ -141,8 +141,7 @@ free_percent | 1.95
<para>
<function>pgstatindex</function> returns a record showing information
about a btree index. For example:
</para>
<programlisting>
<programlisting>
test=> SELECT * FROM pgstatindex('pg_cast_oid_index');
-[ RECORD 1 ]------+------
version | 2
@ -155,7 +154,8 @@ empty_pages | 0
deleted_pages | 0
avg_leaf_density | 50.27
leaf_fragmentation | 0
</programlisting>
</programlisting>
</para>
<para>
The output columns are:

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgtrgm.sgml,v 2.2 2007/12/10 05:32:51 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgtrgm.sgml,v 2.3 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="pgtrgm">
<title>pg_trgm</title>
@ -136,27 +136,25 @@
<para>
Example:
<programlisting>
<programlisting>
CREATE TABLE test_trgm (t text);
CREATE INDEX trgm_idx ON test_trgm USING gist (t gist_trgm_ops);
</programlisting>
</programlisting>
or
<programlisting>
<programlisting>
CREATE INDEX trgm_idx ON test_trgm USING gin (t gin_trgm_ops);
</programlisting>
</programlisting>
</para>
<para>
At this point, you will have an index on the <structfield>t</> column that
you can use for similarity searching. A typical query is
</para>
<programlisting>
<programlisting>
SELECT t, similarity(t, '<replaceable>word</>') AS sml
FROM test_trgm
WHERE t % '<replaceable>word</>'
ORDER BY sml DESC, t;
</programlisting>
<para>
</programlisting>
This will return all values in the text column that are sufficiently
similar to <replaceable>word</>, sorted from best match to worst. The
index will be used to make this a fast operation even over very large data
@ -185,14 +183,12 @@ SELECT t, similarity(t, '<replaceable>word</>') AS sml
<para>
The first step is to generate an auxiliary table containing all
the unique words in the documents:
</para>
<programlisting>
<programlisting>
CREATE TABLE words AS SELECT word FROM
ts_stat('SELECT to_tsvector(''simple'', bodytext) FROM documents');
</programlisting>
</programlisting>
<para>
where <structname>documents</> is a table that has a text field
<structfield>bodytext</> that we wish to search. The reason for using
the <literal>simple</> configuration with the <function>to_tsvector</>
@ -202,13 +198,11 @@ CREATE TABLE words AS SELECT word FROM
<para>
Next, create a trigram index on the word column:
</para>
<programlisting>
<programlisting>
CREATE INDEX words_idx ON words USING gin(word gin_trgm_ops);
</programlisting>
</programlisting>
<para>
Now, a <command>SELECT</command> query similar to the previous example can
be used to suggest spellings for misspelled words in user search terms.
A useful extra test is to require that the selected words are also of

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.86 2010/07/08 21:35:33 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.87 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="plperl">
<title>PL/Perl - Perl Procedural Language</title>
@ -530,10 +530,7 @@ $plan = spi_prepare('SELECT * FROM test WHERE id &gt; $1 AND name = $2',
The advantage of prepared queries is that is it possible to use one prepared plan for more
than one query execution. After the plan is not needed anymore, it can be freed with
<literal>spi_freeplan</literal>:
</para>
<para>
<programlisting>
<programlisting>
CREATE OR REPLACE FUNCTION init() RETURNS VOID AS $$
$_SHARED{my_plan} = spi_prepare('SELECT (now() + $1)::date AS now',
'INTERVAL');
@ -558,10 +555,7 @@ SELECT done();
add_time | add_time | add_time
------------+------------+------------
2005-12-10 | 2005-12-11 | 2005-12-12
</programlisting>
</para>
<para>
</programlisting>
Note that the parameter subscript in <literal>spi_prepare</literal> is defined via
$1, $2, $3, etc, so avoid declaring query strings in double quotes that might easily
lead to hard-to-catch bugs.
@ -569,15 +563,12 @@ SELECT done();
<para>
Another example illustrates usage of an optional parameter in <literal>spi_exec_prepared</literal>:
</para>
<para>
<programlisting>
<programlisting>
CREATE TABLE hosts AS SELECT id, ('192.168.1.'||id)::inet AS address
FROM generate_series(1,3) AS id;
CREATE OR REPLACE FUNCTION init_hosts_query() RETURNS VOID AS $$
$_SHARED{plan} = spi_prepare('SELECT * FROM hosts
$_SHARED{plan} = spi_prepare('SELECT * FROM hosts
WHERE address &lt;&lt; $1', 'inet');
$$ LANGUAGE plperl;
@ -603,7 +594,7 @@ SELECT release_hosts_query();
(1,192.168.1.1)
(2,192.168.1.2)
(2 rows)
</programlisting>
</programlisting>
</para>
</listitem>
</varlistentry>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.155 2010/07/27 20:02:06 rhaas Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.156 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="plpgsql">
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@ -1217,14 +1217,14 @@ EXECUTE 'UPDATE tbl SET '
As always, care must be taken to ensure that null values in a query do
not deliver unintended results. For example the <literal>WHERE</> clause
<programlisting>
'WHERE key = ' || quote_nullable(keyvalue)
'WHERE key = ' || quote_nullable(keyvalue)
</programlisting>
will never succeed if <literal>keyvalue</> is null, because the
result of using the equality operator <literal>=</> with a null operand
is always null. If you wish null to work like an ordinary key value,
you would need to rewrite the above as
<programlisting>
'WHERE key IS NOT DISTINCT FROM ' || quote_nullable(keyvalue)
'WHERE key IS NOT DISTINCT FROM ' || quote_nullable(keyvalue)
</programlisting>
(At present, <literal>IS NOT DISTINCT FROM</> is handled much less
efficiently than <literal>=</>, so don't do this unless you must.
@ -1391,20 +1391,20 @@ NULL;
<para>
For example, the following two fragments of code are equivalent:
<programlisting>
BEGIN
y := x / 0;
EXCEPTION
WHEN division_by_zero THEN
NULL; -- ignore the error
END;
BEGIN
y := x / 0;
EXCEPTION
WHEN division_by_zero THEN
NULL; -- ignore the error
END;
</programlisting>
<programlisting>
BEGIN
y := x / 0;
EXCEPTION
WHEN division_by_zero THEN -- ignore the error
END;
BEGIN
y := x / 0;
EXCEPTION
WHEN division_by_zero THEN -- ignore the error
END;
</programlisting>
Which is preferable is a matter of taste.
</para>
@ -2275,8 +2275,8 @@ END;
not case-sensitive. Also, an error condition can be specified
by <literal>SQLSTATE</> code; for example these are equivalent:
<programlisting>
WHEN division_by_zero THEN ...
WHEN SQLSTATE '22012' THEN ...
WHEN division_by_zero THEN ...
WHEN SQLSTATE '22012' THEN ...
</programlisting>
</para>
@ -2295,16 +2295,16 @@ END;
As an example, consider this fragment:
<programlisting>
INSERT INTO mytab(firstname, lastname) VALUES('Tom', 'Jones');
BEGIN
UPDATE mytab SET firstname = 'Joe' WHERE lastname = 'Jones';
x := x + 1;
y := x / 0;
EXCEPTION
WHEN division_by_zero THEN
RAISE NOTICE 'caught division_by_zero';
RETURN x;
END;
INSERT INTO mytab(firstname, lastname) VALUES('Tom', 'Jones');
BEGIN
UPDATE mytab SET firstname = 'Joe' WHERE lastname = 'Jones';
x := x + 1;
y := x / 0;
EXCEPTION
WHEN division_by_zero THEN
RAISE NOTICE 'caught division_by_zero';
RETURN x;
END;
</programlisting>
When control reaches the assignment to <literal>y</>, it will
@ -3519,7 +3519,7 @@ SELECT * FROM sales_summary_bytime;
column reference is syntactically allowed. As an extreme case, consider
this example of poor programming style:
<programlisting>
INSERT INTO foo (foo) VALUES (foo);
INSERT INTO foo (foo) VALUES (foo);
</programlisting>
The first occurrence of <literal>foo</> must syntactically be a table
name, so it will not be substituted, even if the function has a variable
@ -3542,7 +3542,7 @@ SELECT * FROM sales_summary_bytime;
tables: is a given name meant to refer to a table column, or a variable?
Let's change the previous example to
<programlisting>
INSERT INTO dest (col) SELECT foo + bar FROM src;
INSERT INTO dest (col) SELECT foo + bar FROM src;
</programlisting>
Here, <literal>dest</> and <literal>src</> must be table names, and
<literal>col</> must be a column of <literal>dest</>, but <literal>foo</>
@ -3575,12 +3575,12 @@ SELECT * FROM sales_summary_bytime;
declare it in a labeled block and use the block's label
(see <xref linkend="plpgsql-structure">). For example,
<programlisting>
&lt;&lt;block&gt;&gt;
DECLARE
foo int;
BEGIN
foo := ...;
INSERT INTO dest (col) SELECT block.foo + bar FROM src;
&lt;&lt;block&gt;&gt;
DECLARE
foo int;
BEGIN
foo := ...;
INSERT INTO dest (col) SELECT block.foo + bar FROM src;
</programlisting>
Here <literal>block.foo</> means the variable even if there is a column
<literal>foo</> in <literal>src</>. Function parameters, as well as
@ -4591,17 +4591,17 @@ $$ LANGUAGE plpgsql;
is equivalent to what you'd get in Oracle with:
<programlisting>
BEGIN
SAVEPOINT s1;
BEGIN
SAVEPOINT s1;
... code here ...
EXCEPTION
WHEN ... THEN
ROLLBACK TO s1;
... code here ...
EXCEPTION
WHEN ... THEN
ROLLBACK TO s1;
... code here ...
WHEN ... THEN
ROLLBACK TO s1;
... code here ...
END;
WHEN ... THEN
ROLLBACK TO s1;
... code here ...
END;
</programlisting>
If you are translating an Oracle procedure that uses

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_domain.sgml,v 1.25 2010/04/03 07:22:56 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_domain.sgml,v 1.26 2010/07/29 19:34:40 petere Exp $
PostgreSQL documentation
-->
@ -22,7 +22,7 @@ PostgreSQL documentation
</indexterm>
<refsynopsisdiv>
<synopsis>
<synopsis>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
{ SET DEFAULT <replaceable class="PARAMETER">expression</replaceable> | DROP DEFAULT }
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
@ -35,7 +35,7 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
</synopsis>
</synopsis>
</refsynopsisdiv>
<refsect1>
@ -214,34 +214,34 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
<para>
To add a <literal>NOT NULL</literal> constraint to a domain:
<programlisting>
<programlisting>
ALTER DOMAIN zipcode SET NOT NULL;
</programlisting>
</programlisting>
To remove a <literal>NOT NULL</literal> constraint from a domain:
<programlisting>
<programlisting>
ALTER DOMAIN zipcode DROP NOT NULL;
</programlisting>
</programlisting>
</para>
<para>
<para>
To add a check constraint to a domain:
<programlisting>
<programlisting>
ALTER DOMAIN zipcode ADD CONSTRAINT zipchk CHECK (char_length(VALUE) = 5);
</programlisting>
</programlisting>
</para>
<para>
<para>
To remove a check constraint from a domain:
<programlisting>
<programlisting>
ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;
</programlisting>
</programlisting>
</para>
<para>
To move the domain into a different schema:
<programlisting>
<programlisting>
ALTER DOMAIN zipcode SET SCHEMA customers;
</programlisting>
</programlisting>
</para>
</refsect1>

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.25 2010/04/03 07:22:57 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.26 2010/07/29 19:34:40 petere Exp $
PostgreSQL documentation
-->
@ -22,7 +22,7 @@ PostgreSQL documentation
</indexterm>
<refsynopsisdiv>
<synopsis>
<synopsis>
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE ]
[ START [ WITH ] <replaceable class="parameter">start</replaceable> ]
@ -32,7 +32,7 @@ ALTER SEQUENCE <replaceable class="parameter">name</replaceable> [ INCREMENT [ B
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
</synopsis>
</synopsis>
</refsynopsisdiv>
<refsect1>

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_type.sgml,v 1.8 2010/04/03 07:22:57 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_type.sgml,v 1.9 2010/07/29 19:34:40 petere Exp $
PostgreSQL documentation
-->
@ -22,11 +22,11 @@ PostgreSQL documentation
</indexterm>
<refsynopsisdiv>
<synopsis>
<synopsis>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
</synopsis>
</synopsis>
</refsynopsisdiv>
<refsect1>
@ -97,27 +97,27 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replace
<refsect1>
<title>Examples</title>
<para>
<para>
To rename a data type:
<programlisting>
<programlisting>
ALTER TYPE electronic_mail RENAME TO email;
</programlisting>
</programlisting>
</para>
<para>
<para>
To change the owner of the type <literal>email</literal>
to <literal>joe</literal>:
<programlisting>
<programlisting>
ALTER TYPE email OWNER TO joe;
</programlisting>
</programlisting>
</para>
<para>
To change the schema of the type <literal>email</literal>
to <literal>customers</literal>:
<programlisting>
<programlisting>
ALTER TYPE email SET SCHEMA customers;
</programlisting>
</programlisting>
</para>
</refsect1>

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.74 2010/04/03 07:22:58 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.75 2010/07/29 19:34:40 petere Exp $
PostgreSQL documentation
-->
@ -557,12 +557,12 @@ CREATE INDEX code_idx ON films (code) TABLESPACE indexspace;
To create a GiST index on a point attribute so that we
can efficiently use box operators on the result of the
conversion function:
<programlisting>
<programlisting>
CREATE INDEX pointloc
ON points USING gist (box(location,location));
SELECT * FROM points
WHERE box(location,location) &amp;&amp; '(0,0),(1,1)'::box;
</programlisting>
</programlisting>
</para>
<para>

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/grant.sgml,v 1.83 2010/04/03 07:23:01 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/grant.sgml,v 1.84 2010/07/29 19:34:41 petere Exp $
PostgreSQL documentation
-->
@ -492,27 +492,27 @@ GRANT <replaceable class="PARAMETER">role_name</replaceable> [, ...] TO <replace
(1 row)
</programlisting>
The entries shown by <command>\dp</command> are interpreted thus:
<programlisting>
rolename=xxxx -- privileges granted to a role
=xxxx -- privileges granted to PUBLIC
<literallayout class="monospaced">
rolename=xxxx -- privileges granted to a role
=xxxx -- privileges granted to PUBLIC
r -- SELECT ("read")
w -- UPDATE ("write")
a -- INSERT ("append")
d -- DELETE
D -- TRUNCATE
x -- REFERENCES
t -- TRIGGER
X -- EXECUTE
U -- USAGE
C -- CREATE
c -- CONNECT
T -- TEMPORARY
arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects)
* -- grant option for preceding privilege
r -- SELECT ("read")
w -- UPDATE ("write")
a -- INSERT ("append")
d -- DELETE
D -- TRUNCATE
x -- REFERENCES
t -- TRIGGER
X -- EXECUTE
U -- USAGE
C -- CREATE
c -- CONNECT
T -- TEMPORARY
arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects)
* -- grant option for preceding privilege
/yyyy -- role that granted this privilege
</programlisting>
/yyyy -- role that granted this privilege
</literallayout>
The above example display would be seen by user <literal>miriam</> after
creating table <literal>mytable</> and doing:

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/release-8.1.sgml,v 1.7 2010/05/13 21:26:59 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/release-8.1.sgml,v 1.8 2010/07/29 19:34:40 petere Exp $ -->
<!-- See header comment in release.sgml about typical markup -->
<sect1 id="release-8-1-21">
@ -4040,9 +4040,9 @@ psql -t -f fixseq.sql db1 | psql -e db1
Previously, only a predefined list of time zone names were
supported by <command>AT TIME ZONE</>. Now any supported time
zone name can be used, e.g.:
<programlisting>
SELECT CURRENT_TIMESTAMP AT TIME ZONE 'Europe/London';
</programlisting>
<programlisting>
SELECT CURRENT_TIMESTAMP AT TIME ZONE 'Europe/London';
</programlisting>
In the above query, the time zone used is adjusted based on the
daylight saving time rules that were in effect on the supplied
date.
@ -4116,10 +4116,10 @@ psql -t -f fixseq.sql db1 | psql -e db1
the next day even if a daylight saving time adjustment occurs
between, whereas adding <literal>24 hours</> will give a different
local time when this happens. For example, under US DST rules:
<programlisting>
'2005-04-03 00:00:00-05' + '1 day' = '2005-04-04 00:00:00-04'
'2005-04-03 00:00:00-05' + '24 hours' = '2005-04-04 01:00:00-04'
</programlisting>
<programlisting>
'2005-04-03 00:00:00-05' + '1 day' = '2005-04-04 00:00:00-04'
'2005-04-03 00:00:00-05' + '24 hours' = '2005-04-04 01:00:00-04'
</programlisting>
</para>
</listitem>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/release-old.sgml,v 1.1 2009/05/02 20:17:19 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/release-old.sgml,v 1.2 2010/07/29 19:34:40 petere Exp $ -->
<!-- See header comment in release.sgml about typical markup -->
<sect1 id="release-7-3-21">
@ -2919,7 +2919,7 @@ since <productname>PostgreSQL</productname> 7.1.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Remove unused WAL segments of large transactions (Tom)
Multiaction rule fix (Tom)
PL/pgSQL memory allocation fix (Jan)
@ -2930,7 +2930,7 @@ Fix subselects with DISTINCT ON or LIMIT (Tom)
BeOS fix
Disable COPY TO/FROM a view (Tom)
Cygwin build (Jason Tishler)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -2962,13 +2962,13 @@ Cygwin build (Jason Tishler)
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Fix PL/pgSQL SELECTs when returning no rows
Fix for psql backslash core dump
Referential integrity privilege fix
Optimizer fixes
pg_dump cleanups
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -3000,7 +3000,7 @@ pg_dump cleanups
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Fix for numeric MODULO operator (Tom)
pg_dump fixes (Philip)
pg_dump can dump 7.0 databases (Philip)
@ -3015,7 +3015,7 @@ Fix for pg_ctl and option strings with spaces (Peter E)
ODBC fixes (Hiroshi)
EXTRACT can now take string argument (Thomas)
Python fixes (Darcy)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -3127,7 +3127,7 @@ Subqueries in FROM are now supported.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
Many multibyte/Unicode/locale fixes (Tatsuo and others)
@ -3313,7 +3313,7 @@ New contrib/pg_logger
New --template option to createdb
New contrib/pg_control utility (Oliver)
New FreeBSD tools ipc_check, start-scripts/freebsd
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -3345,7 +3345,7 @@ New FreeBSD tools ipc_check, start-scripts/freebsd
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Jdbc fixes (Peter)
Large object fix (Tom)
Fix lean in COPY WITH OIDS leak (Tom)
@ -3385,7 +3385,7 @@ Buffer fix (Tom)
Fix for inserting/copying longer multibyte strings into char() data
types (Tatsuo)
Fix for crash of backend, on abort (Tom)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -3417,9 +3417,9 @@ Fix for crash of backend, on abort (Tom)
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Added documentation to tarball.
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -3450,7 +3450,7 @@ Added documentation to tarball.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Fix many CLUSTER failures (Tom)
Allow ALTER TABLE RENAME works on indexes (Tom)
Fix plpgsql to handle datetime-&gt;timestamp and timespan-&gt;interval (Bruce)
@ -3475,7 +3475,7 @@ Fix too long syslog message (Tatsuo)
Fix problem with quoted indexes that are too long (Tom)
JDBC ResultSet.getTimestamp() fix (Gregory Krasnow &amp; Floyd Marinescu)
ecpg changes (Michael)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -3626,7 +3626,7 @@ ecpg changes (Michael)
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
Prevent function calls exceeding maximum number of arguments (Tom)
@ -3944,7 +3944,7 @@ NT fixes
NetBSD fixes (Johnny C. Lam <email>lamj@stat.cmu.edu</email>)
Fixes for Alpha compiles
New multibyte encodings
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -3975,11 +3975,11 @@ New multibyte encodings
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Updated version of pgaccess 0.98
NT-specific patch
Fix dumping rules on inherited tables
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -4012,7 +4012,7 @@ Fix dumping rules on inherited tables
<title>Changes</title>
<para>
<programlisting>
<programlisting>
subselect+CASE fixes(Tom)
Add SHLIB_LINK setting for solaris_i386 and solaris_sparc ports(Daren Sefcik)
Fixes for CASE in WHERE join clauses(Tom)
@ -4037,7 +4037,7 @@ Repair logic error in LIKE: should not return LIKE_ABORT
when reach end of pattern before end of text(Tom)
Repair incorrect cleanup of heap memory allocation during transaction abort(Tom)
Updated version of pgaccess 0.98
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -4068,7 +4068,7 @@ Updated version of pgaccess 0.98
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Add NT README file
Portability fixes for linux_ppc, IRIX, linux_alpha, OpenBSD, alpha
Remove QUERY_LIMIT, use SELECT...LIMIT
@ -4092,7 +4092,7 @@ Shared library dependencies fixed (Tom)
Fixed glitches affecting GROUP BY in subselects(Tom)
Fix some compiler warnings (Tomoaki Nishiyama)
Add Win1250 (Czech) support (Pavel Behal)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -4329,7 +4329,7 @@ Add Win1250 (Czech) support (Pavel Behal)
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
Fix text&lt;-&gt;float8 and text&lt;-&gt;float4 conversion functions(Thomas)
@ -4491,7 +4491,7 @@ Add ARM32 support(Andrew McMurry)
Better support for HP-UX 11 and UnixWare
Improve file handling to be more uniform, prevent file descriptor leak(Tom)
New install commands for plpgsql(Jan)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -4695,7 +4695,7 @@ previous release of <productname>PostgreSQL</productname>.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
Fix for a tiny memory leak in PQsetdb/PQfinish(Bryan)
@ -4939,7 +4939,7 @@ refer to the installation and migration instructions for version 6.3.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Configure detection improvements for tcl/tk(Brook Milligan, Alvin)
Manual page improvements(Bruce)
BETWEEN and LIKE fix(Thomas)
@ -4958,7 +4958,7 @@ libreadline cleanup(Erwan MAS)
Remove DISTDIR(Bruce)
Makefile dependency cleanup(Jeroen van Vianen)
ASSERT fixes(Bruce)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -5016,7 +5016,7 @@ refer to the installation and migration instructions for version 6.3.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
ecpg cleanup/fixes, now version 1.1(Michael Meskes)
pg_user cleanup(Bruce)
large object fix for pg_dump and tclsh (alvin)
@ -5044,7 +5044,7 @@ Fix Alpha port(Dwayne Bailey)
Fix for text arrays containing quotes(Doug Gibson)
Solaris compile fix(Albert Chin-A-Young)
Better identify tcl and tk libs and includes(Bruce)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -5191,7 +5191,7 @@ Better identify tcl and tk libs and includes(Bruce)
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
Fix binary cursors broken by MOVE implementation(Vadim)
@ -5413,8 +5413,8 @@ Another way to avoid dump/reload is to use the following SQL command
from <command>psql</command> to update the existing system table:
<programlisting>
update pg_aggregate set aggfinalfn = 'cash_div_flt8'
where aggname = 'avg' and aggbasetype = 790;
update pg_aggregate set aggfinalfn = 'cash_div_flt8'
where aggname = 'avg' and aggbasetype = 790;
</programlisting>
</para>
<para>
@ -5426,7 +5426,7 @@ This will need to be done to every existing database, including template1.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Allow TIME and TYPE column names(Thomas)
Allow larger range of true/false as boolean values(Thomas)
Support output of "now" and "current"(Thomas)
@ -5438,7 +5438,7 @@ Fix avg(cash) computation(Thomas)
Fix for specifying a column twice in ORDER/GROUP BY(Vadim)
Documented new libpq function to return affected rows, PQcmdTuples(Bruce)
Trigger function for inserting user names for INSERT/UPDATE(Brook Milligan)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -5482,7 +5482,7 @@ because the COPY output format was improved from the 1.02 release.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
Fix problems with pg_dump for inheritance, sequences, archive tables(Bruce)
@ -5618,7 +5618,7 @@ Refer to the release notes for 6.1 for more details.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
fix for SET with options (Thomas)
allow pg_dump/pg_dumpall to preserve ownership of all tables/objects(Bruce)
new psql \connect option allows changing usernames without changing databases
@ -5636,7 +5636,7 @@ major fix for endian handling of communication to server(Thomas, Tatsuo)
Fix for Solaris assembler and include files(Yoshihiko Ichikawa)
allow underscores in usernames(Bruce)
pg_dumpall now returns proper status, portability fix(Bruce)
</programlisting>
</programlisting>
</para>
</sect2>
</sect1>
@ -5713,7 +5713,7 @@ because the COPY output format was improved from the 1.02 release.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
packet length checking in library routines
@ -5848,7 +5848,7 @@ because the COPY output format was improved from the 1.02 release.
<title>Changes</title>
<para>
<programlisting>
<programlisting>
Bug Fixes
---------
ALTER TABLE bug - running postgres process needs to re-read table definition
@ -6017,7 +6017,7 @@ Add the new built-in functions and operators of 1.02.1 to 1.01 or 1.02
1.01 or 1.02 database is named <literal>testdb</literal> and you have cut the commands
from the end of this file and saved them in <filename>addfunc.sql</filename>:
<programlisting>
% psql testdb -f addfunc.sql
% psql testdb -f addfunc.sql
</programlisting>
Those upgrading 1.02 databases will get a warning when executing the
@ -6040,7 +6040,7 @@ end-of-data marker. Also, empty strings are now loaded in as '' rather
than NULL. See the copy manual page for full details.
<programlisting>
sed 's/^\.$/\\./g' &lt;in_file &gt;out_file
sed 's/^\.$/\\./g' &lt;in_file &gt;out_file
</programlisting>
</para>
<para>
@ -6169,7 +6169,7 @@ If you do, you must create a file name <literal>pg_hba</literal> in your top-lev
If you do not want host-based authentication, you can comment out
the line:
<programlisting>
HBA = 1
HBA = 1
</programlisting>
in <filename>src/Makefile.global</filename>
</para>
@ -6218,7 +6218,7 @@ Add the new built-in functions and operators of 1.01 to 1.0
If your 1.0 database is name <literal>testdb</literal>:
<programlisting>
% psql testdb -f 1.0_to_1.01.sql
% psql testdb -f 1.0_to_1.01.sql
</programlisting>
and then execute the following commands (cut and paste from here):
@ -6563,11 +6563,11 @@ Initial release.
<para>
These timing results are from running the regression test with the commands
<programlisting>
<programlisting>
% cd src/test/regress
% make all
% time make runtest
</programlisting>
</programlisting>
</para>
<para>
Timing under Linux 2.0.27 seems to have a roughly 5% variation from run
@ -6587,20 +6587,20 @@ Initial release.
<para>
Timing with <function>fsync()</function> disabled:
<programlisting>
Time System
02:00 Dual Pentium Pro 180, 224MB, UW-SCSI, Linux 2.0.36, gcc 2.7.2.3 -O2 -m486
04:38 Sparc Ultra 1 143MHz, 64MB, Solaris 2.6
</programlisting>
<literallayout class="monospaced">
Time System
02:00 Dual Pentium Pro 180, 224MB, UW-SCSI, Linux 2.0.36, gcc 2.7.2.3 -O2 -m486
04:38 Sparc Ultra 1 143MHz, 64MB, Solaris 2.6
</literallayout>
</para>
<para>
Timing with <function>fsync()</function> enabled:
<programlisting>
Time System
04:21 Dual Pentium Pro 180, 224MB, UW-SCSI, Linux 2.0.36, gcc 2.7.2.3 -O2 -m486
</programlisting>
<literallayout class="monospaced">
Time System
04:21 Dual Pentium Pro 180, 224MB, UW-SCSI, Linux 2.0.36, gcc 2.7.2.3 -O2 -m486
</literallayout>
For the <systemitem class="osname">Linux</systemitem> system above, using <acronym>UW-SCSI</acronym> disks rather than (older) <acronym>IDE</acronym>
disks leads to a 50% improvement in speed on the regression test.
@ -6616,10 +6616,10 @@ since some additional regression tests have been included.
In general, however, 6.4 should be slightly faster than the previous release (thanks, Bruce!).
</para>
<para>
<programlisting>
Time System
02:26 Dual Pentium Pro 180, 96MB, UW-SCSI, Linux 2.0.30, gcc 2.7.2.1 -O2 -m486
</programlisting>
<literallayout class="monospaced">
Time System
02:26 Dual Pentium Pro 180, 96MB, UW-SCSI, Linux 2.0.30, gcc 2.7.2.1 -O2 -m486
</literallayout>
</para>
</sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/seg.sgml,v 1.6 2009/12/08 20:08:30 mha Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/seg.sgml,v 1.7 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="seg">
<title>seg</title>
@ -39,13 +39,13 @@
6.50, and you input this reading into the database. What do you get
when you fetch it? Watch:
<programlisting>
<screen>
test=> select 6.50 :: float8 as "pH";
pH
---
6.5
(1 row)
</programlisting>
</screen>
In the world of measurements, 6.50 is not the same as 6.5. It may
sometimes be critically different. The experimenters usually write
@ -65,13 +65,13 @@ test=> select 6.50 :: float8 as "pH";
<para>
Check this out:
<programlisting>
<screen>
test=> select '6.25 .. 6.50'::seg as "pH";
pH
------------
6.25 .. 6.50
(1 row)
</programlisting>
</screen>
</para>
</sect2>
@ -234,85 +234,75 @@ test=> select '6.25 .. 6.50'::seg as "pH";
<para>
The <filename>seg</> module includes a GiST index operator class for
<type>seg</> values.
The operators supported by the GiST opclass include:
The operators supported by the GiST opclass are shown in <xref linkend="seg-gist-operators">.
</para>
<itemizedlist>
<listitem>
<programlisting>
[a, b] &lt;&lt; [c, d] Is left of
</programlisting>
<para>
[a, b] is entirely to the left of [c, d]. That is,
[a, b] &lt;&lt; [c, d] is true if b &lt; c and false otherwise
</para>
</listitem>
<listitem>
<programlisting>
[a, b] &gt;&gt; [c, d] Is right of
</programlisting>
<para>
[a, b] is entirely to the right of [c, d]. That is,
[a, b] &gt;&gt; [c, d] is true if a &gt; d and false otherwise
</para>
</listitem>
<listitem>
<programlisting>
[a, b] &amp;&lt; [c, d] Overlaps or is left of
</programlisting>
<para>
This might be better read as <quote>does not extend to right of</quote>.
It is true when b &lt;= d.
</para>
</listitem>
<listitem>
<programlisting>
[a, b] &amp;&gt; [c, d] Overlaps or is right of
</programlisting>
<para>
This might be better read as <quote>does not extend to left of</quote>.
It is true when a &gt;= c.
</para>
</listitem>
<listitem>
<programlisting>
[a, b] = [c, d] Same as
</programlisting>
<para>
The segments [a, b] and [c, d] are identical, that is, a = c and b = d
</para>
</listitem>
<listitem>
<programlisting>
[a, b] &amp;&amp; [c, d] Overlaps
</programlisting>
<para>
The segments [a, b] and [c, d] overlap.
</para>
</listitem>
<listitem>
<programlisting>
[a, b] @&gt; [c, d] Contains
</programlisting>
<para>
The segment [a, b] contains the segment [c, d], that is,
a &lt;= c and b &gt;= d
</para>
</listitem>
<listitem>
<programlisting>
[a, b] &lt;@ [c, d] Contained in
</programlisting>
<para>
The segment [a, b] is contained in [c, d], that is,
a &gt;= c and b &lt;= d
</para>
</listitem>
</itemizedlist>
<table id="seg-gist-operators">
<title>Seg GiST operators</title>
<tgroup cols="2">
<thead>
<row>
<entry>Operator</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>[a, b] &lt;&lt; [c, d]</literal></entry>
<entry>[a, b] is entirely to the left of [c, d]. That is, [a,
b] &lt;&lt; [c, d] is true if b &lt; c and false otherwise.</entry>
</row>
<row>
<entry><literal>[a, b] &gt;&gt; [c, d]</literal></entry>
<entry>[a, b] is entirely to the right of [c, d]. That is, [a,
b] &gt;&gt; [c, d] is true if a &gt; d and false otherwise.</entry>
</row>
<row>
<entry><literal>[a, b] &amp;&lt; [c, d]</literal></entry>
<entry>Overlaps or is left of &mdash; This might be better read
as <quote>does not extend to right of</quote>. It is true when
b &lt;= d.</entry>
</row>
<row>
<entry><literal>[a, b] &amp;&gt; [c, d]</literal></entry>
<entry>Overlaps or is right of &mdash; This might be better read
as <quote>does not extend to left of</quote>. It is true when
a &gt;= c.</entry>
</row>
<row>
<entry><literal>[a, b] = [c, d]</literal></entry>
<entry>Same as &mdash; The segments [a, b] and [c, d] are
identical, that is, a = c and b = d.</entry>
</row>
<row>
<entry><literal>[a, b] &amp;&amp; [c, d]</literal></entry>
<entry>The segments [a, b] and [c, d] overlap.</entry>
</row>
<row>
<entry><literal>[a, b] @&gt; [c, d]</literal></entry>
<entry>The segment [a, b] contains the segment [c, d], that is,
a &lt;= c and b &gt;= d.</entry>
</row>
<row>
<entry><literal>[a, b] &lt;@ [c, d]</literal></entry>
<entry>The segment [a, b] is contained in [c, d], that is, a
&gt;= c and b &lt;= d.</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
(Before PostgreSQL 8.2, the containment operators @&gt; and &lt;@ were
respectively called @ and ~. These names are still available, but are
(Before PostgreSQL 8.2, the containment operators <literal>@&gt;</> and <literal>&lt;@</> were
respectively called <literal>@</> and <literal>~</>. These names are still available, but are
deprecated and will eventually be retired. Notice that the old names
are reversed from the convention formerly followed by the core geometric
datatypes!)
@ -321,10 +311,28 @@ test=> select '6.25 .. 6.50'::seg as "pH";
<para>
The standard B-tree operators are also provided, for example
<programlisting>
[a, b] &lt; [c, d] Less than
[a, b] &gt; [c, d] Greater than
</programlisting>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Operator</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>[a, b] &lt; [c, d]</literal></entry>
<entry>Less than</entry>
</row>
<row>
<entry><literal>[a, b] &gt; [c, d]</literal></entry>
<entry>Greater than</entry>
</row>
</tbody>
</tgroup>
</informaltable>
These operators do not make a lot of sense for any practical
purpose but sorting. These operators first compare (a) to (c),
@ -347,12 +355,12 @@ test=> select '6.25 .. 6.50'::seg as "pH";
for the boundaries. For example, it adds an extra digit to the lower
boundary if the resulting interval includes a power of ten:
<programlisting>
<screen>
postgres=> select '10(+-)1'::seg as seg;
seg
---------
9.0 .. 11 -- should be: 9 .. 11
</programlisting>
</screen>
</para>
<para>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/sql.sgml,v 1.48 2009/04/27 16:27:36 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/sql.sgml,v 1.49 2010/07/29 19:34:40 petere Exp $ -->
<chapter id="sql-intro">
<title>SQL</title>
@ -151,7 +151,7 @@
<example>
<title id="supplier-fig">The Suppliers and Parts Database</title>
<programlisting>
<screen>
SUPPLIER: SELLS:
SNO | SNAME | CITY SNO | PNO
----+---------+-------- -----+-----
@ -168,7 +168,7 @@ PART: 4 | 3
2 | Nut | 8
3 | Bolt | 15
4 | Cam | 25
</programlisting>
</screen>
</example>
</para>
@ -530,14 +530,14 @@ attributes are taken from. We often write a relation scheme as
necessary for a join.
Let the following two tables be given:
<programlisting>
<screen>
R: S:
A | B | C C | D | E
---+---+--- ---+---+---
1 | 2 | 3 3 | a | b
4 | 5 | 6 6 | c | d
7 | 8 | 9
</programlisting>
</screen>
</para>
</example>
@ -546,7 +546,7 @@ R: S:
<classname>R</classname> &times; <classname>S</classname> and
get:
<programlisting>
<screen>
R x S:
A | B | R.C | S.C | D | E
---+---+-----+-----+---+---
@ -556,7 +556,7 @@ R x S:
4 | 5 | 6 | 6 | c | d
7 | 8 | 9 | 3 | a | b
7 | 8 | 9 | 6 | c | d
</programlisting>
</screen>
</para>
<para>
@ -564,12 +564,12 @@ R x S:
&sigma;<subscript>R.C=S.C</subscript>(R &times; S)
we get:
<programlisting>
<screen>
A | B | R.C | S.C | D | E
---+---+-----+-----+---+---
1 | 2 | 3 | 3 | a | b
4 | 5 | 6 | 6 | c | d
</programlisting>
</screen>
</para>
<para>
@ -579,12 +579,12 @@ R x S:
&pi;<subscript>R.A,R.B,R.C,S.D,S.E</subscript>(&sigma;<subscript>R.C=S.C</subscript>(R &times; S))
and get:
<programlisting>
<screen>
A | B | C | D | E
---+---+---+---+---
1 | 2 | 3 | a | b
4 | 5 | 6 | c | d
</programlisting>
</screen>
</para>
</listitem>
@ -596,9 +596,9 @@ R x S:
C and D.
Then we define the division as:
<programlisting>
<programlisting>
R &divide; S = {t &mid; &forall; t<subscript>s</subscript> &isin; S &exist; t<subscript>r</subscript> &isin; R
</programlisting>
</programlisting>
such that
t<subscript>r</subscript>(A,B)=t&and;t<subscript>r</subscript>(C,D)=t<subscript>s</subscript>}
@ -615,7 +615,7 @@ t<subscript>r</subscript>(A,B)=t&and;t<subscript>r</subscript>(C,D)=t<subscript>
<para id="divide-example">
Given the following tables
<programlisting>
<screen>
R: S:
A | B | C | D C | D
---+---+---+--- ---+---
@ -625,17 +625,17 @@ R: S:
e | d | c | d
e | d | e | f
a | b | d | e
</programlisting>
</screen>
R &divide; S
is derived as
<programlisting>
<screen>
A | B
---+---
a | b
e | d
</programlisting>
</screen>
</para>
</listitem>
</itemizedlist>
@ -659,9 +659,9 @@ R: S:
This question can be answered
using relational algebra by the following operation:
<programlisting>
<programlisting>
&pi;<subscript>SUPPLIER.SNAME</subscript>(&sigma;<subscript>PART.PNAME='Screw'</subscript>(SUPPLIER &prod; SELLS &prod; PART))
</programlisting>
</programlisting>
</para>
<para>
@ -670,12 +670,12 @@ R: S:
(<xref linkend="supplier-fig" endterm="supplier-fig">)
we will obtain the following result:
<programlisting>
<screen>
SNAME
-------
Smith
Adams
</programlisting>
</screen>
</para>
</example>
</sect2>
@ -724,9 +724,9 @@ R: S:
The queries used in <acronym>TRC</acronym> are of the following
form:
<programlisting>
<programlisting>
x(A) &mid; F(x)
</programlisting>
</programlisting>
where <literal>x</literal> is a tuple variable
<classname>A</classname> is a set of attributes and <literal>F</literal> is a
@ -739,12 +739,12 @@ x(A) &mid; F(x)
<xref linkend="suppl-rel-alg" endterm="suppl-rel-alg">
using <acronym>TRC</acronym> we formulate the following query:
<programlisting>
<programlisting>
{x(SNAME) &mid; x &isin; SUPPLIER &and;
&exist; y &isin; SELLS &exist; z &isin; PART (y(SNO)=x(SNO) &and;
z(PNO)=y(PNO) &and;
z(PNAME)='Screw')}
</programlisting>
</programlisting>
</para>
<para>
@ -813,9 +813,9 @@ x(A) &mid; F(x)
to involve
arithmetic operations as well as comparisons, e.g.:
<programlisting>
<programlisting>
A &lt; B + 3.
</programlisting>
</programlisting>
Note
that + or other arithmetic operators appear neither in relational
@ -851,7 +851,7 @@ A &lt; B + 3.
<command>SELECT</command> statement,
used to retrieve data. The syntax is:
<synopsis>
<synopsis>
SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replaceable> [, ...] ) ] ]
* | <replaceable class="PARAMETER">expression</replaceable> [ [ AS ] <replaceable class="PARAMETER">output_name</replaceable> ] [, ...]
[ INTO [ TEMPORARY | TEMP ] [ TABLE ] <replaceable class="PARAMETER">new_table</replaceable> ]
@ -864,7 +864,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
[ LIMIT { <replaceable class="PARAMETER">count</replaceable> | ALL } ]
[ OFFSET <replaceable class="PARAMETER">start</replaceable> ]
[ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] [...] ]
</synopsis>
</synopsis>
</para>
<para>
@ -886,19 +886,19 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
To retrieve all tuples from table PART where the attribute PRICE is
greater than 10 we formulate the following query:
<programlisting>
<programlisting>
SELECT * FROM PART
WHERE PRICE &gt; 10;
</programlisting>
</programlisting>
and get the table:
<programlisting>
<screen>
PNO | PNAME | PRICE
-----+---------+--------
3 | Bolt | 15
4 | Cam | 25
</programlisting>
</screen>
</para>
<para>
@ -907,20 +907,20 @@ SELECT * FROM PART
only the attributes PNAME and PRICE from table PART we use the
statement:
<programlisting>
<programlisting>
SELECT PNAME, PRICE
FROM PART
WHERE PRICE &gt; 10;
</programlisting>
</programlisting>
In this case the result is:
<programlisting>
<screen>
PNAME | PRICE
--------+--------
Bolt | 15
Cam | 25
</programlisting>
</screen>
Note that the <acronym>SQL</acronym> <command>SELECT</command>
corresponds to the <quote>projection</quote> in relational algebra
@ -932,20 +932,20 @@ SELECT PNAME, PRICE
The qualifications in the WHERE clause can also be logically connected
using the keywords OR, AND, and NOT:
<programlisting>
<programlisting>
SELECT PNAME, PRICE
FROM PART
WHERE PNAME = 'Bolt' AND
(PRICE = 0 OR PRICE &lt;= 15);
</programlisting>
</programlisting>
will lead to the result:
<programlisting>
<screen>
PNAME | PRICE
--------+--------
Bolt | 15
</programlisting>
</screen>
</para>
<para>
@ -953,21 +953,21 @@ SELECT PNAME, PRICE
clause. For example if we want to know how much it would cost if we
take two pieces of a part we could use the following query:
<programlisting>
<programlisting>
SELECT PNAME, PRICE * 2 AS DOUBLE
FROM PART
WHERE PRICE * 2 &lt; 50;
</programlisting>
</programlisting>
and we get:
<programlisting>
<screen>
PNAME | DOUBLE
--------+---------
Screw | 20
Nut | 16
Bolt | 30
</programlisting>
</screen>
Note that the word DOUBLE after the keyword AS is the new title of the
second column. This technique can be used for every element of the
@ -992,16 +992,16 @@ SELECT PNAME, PRICE * 2 AS DOUBLE
To join the three tables SUPPLIER, PART and SELLS over their common
attributes we formulate the following statement:
<programlisting>
<programlisting>
SELECT S.SNAME, P.PNAME
FROM SUPPLIER S, PART P, SELLS SE
WHERE S.SNO = SE.SNO AND
P.PNO = SE.PNO;
</programlisting>
</programlisting>
and get the following table as a result:
<programlisting>
<screen>
SNAME | PNAME
-------+-------
Smith | Screw
@ -1012,7 +1012,7 @@ SELECT S.SNAME, P.PNAME
Blake | Nut
Blake | Bolt
Blake | Cam
</programlisting>
</screen>
</para>
<para>
@ -1034,13 +1034,13 @@ SELECT S.SNAME, P.PNAME
<para>
Another way to perform joins is to use the SQL JOIN syntax as follows:
<programlisting>
select sname, pname from supplier
<programlisting>
SELECT sname, pname from supplier
JOIN sells USING (sno)
JOIN part USING (pno);
</programlisting>
</programlisting>
giving again:
<programlisting>
<screen>
sname | pname
-------+-------
Smith | Screw
@ -1052,7 +1052,7 @@ select sname, pname from supplier
Jones | Cam
Blake | Cam
(8 rows)
</programlisting>
</screen>
</para>
<para>
@ -1267,38 +1267,38 @@ select sname, pname from supplier
If we want to know the average cost of all parts in table PART we use
the following query:
<programlisting>
<programlisting>
SELECT AVG(PRICE) AS AVG_PRICE
FROM PART;
</programlisting>
</programlisting>
</para>
<para>
The result is:
<programlisting>
<screen>
AVG_PRICE
-----------
14.5
</programlisting>
</screen>
</para>
<para>
If we want to know how many parts are defined in table PART we use
the statement:
<programlisting>
<programlisting>
SELECT COUNT(PNO)
FROM PART;
</programlisting>
</programlisting>
and get:
<programlisting>
<screen>
COUNT
-------
4
</programlisting>
</screen>
</para>
</example>
@ -1335,23 +1335,23 @@ SELECT COUNT(PNO)
If we want to know how many parts are sold by every supplier we
formulate the query:
<programlisting>
<programlisting>
SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
FROM SUPPLIER S, SELLS SE
WHERE S.SNO = SE.SNO
GROUP BY S.SNO, S.SNAME;
</programlisting>
</programlisting>
and get:
<programlisting>
<screen>
SNO | SNAME | COUNT
-----+-------+-------
1 | Smith | 2
2 | Jones | 1
3 | Adams | 2
4 | Blake | 3
</programlisting>
</screen>
</para>
<para>
@ -1359,7 +1359,7 @@ SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
First the join of the
tables SUPPLIER and SELLS is derived:
<programlisting>
<screen>
S.SNO | S.SNAME | SE.PNO
-------+---------+--------
1 | Smith | 1
@ -1370,14 +1370,14 @@ SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
4 | Blake | 2
4 | Blake | 3
4 | Blake | 4
</programlisting>
</screen>
</para>
<para>
Next we partition the tuples into groups by putting all tuples
together that agree on both attributes S.SNO and S.SNAME:
<programlisting>
<screen>
S.SNO | S.SNAME | SE.PNO
-------+---------+--------
1 | Smith | 1
@ -1391,7 +1391,7 @@ SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
4 | Blake | 2
| 3
| 4
</programlisting>
</screen>
</para>
<para>
@ -1442,23 +1442,23 @@ SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
If we want only those suppliers selling more than one part we use the
query:
<programlisting>
<programlisting>
SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
FROM SUPPLIER S, SELLS SE
WHERE S.SNO = SE.SNO
GROUP BY S.SNO, S.SNAME
HAVING COUNT(SE.PNO) &gt; 1;
</programlisting>
</programlisting>
and get:
<programlisting>
<screen>
SNO | SNAME | COUNT
-----+-------+-------
1 | Smith | 2
3 | Adams | 2
4 | Blake | 3
</programlisting>
</screen>
</para>
</example>
</para>
@ -1481,23 +1481,23 @@ SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
If we want to know all parts having a greater price than the part
named 'Screw' we use the query:
<programlisting>
<programlisting>
SELECT *
FROM PART
WHERE PRICE &gt; (SELECT PRICE FROM PART
WHERE PNAME='Screw');
</programlisting>
</programlisting>
</para>
<para>
The result is:
<programlisting>
<screen>
PNO | PNAME | PRICE
-----+---------+--------
3 | Bolt | 15
4 | Cam | 25
</programlisting>
</screen>
</para>
<para>
@ -1519,13 +1519,13 @@ SELECT *
If we want to know all suppliers that do not sell any part
(e.g., to be able to remove these suppliers from the database) we use:
<programlisting>
<programlisting>
SELECT *
FROM SUPPLIER S
WHERE NOT EXISTS
(SELECT * FROM SELLS SE
WHERE SE.SNO = S.SNO);
</programlisting>
</programlisting>
</para>
<para>
@ -1559,14 +1559,14 @@ SELECT *
If we want to know the highest average part price among all our
suppliers, we cannot write MAX(AVG(PRICE)), but we can write:
<programlisting>
<programlisting>
SELECT MAX(subtable.avgprice)
FROM (SELECT AVG(P.PRICE) AS avgprice
FROM SUPPLIER S, PART P, SELLS SE
WHERE S.SNO = SE.SNO AND
P.PNO = SE.PNO
GROUP BY S.SNO) subtable;
</programlisting>
</programlisting>
The subquery returns one row per supplier (because of its GROUP BY)
and then we aggregate over those rows in the outer query.
@ -1588,7 +1588,7 @@ SELECT MAX(subtable.avgprice)
<para>
The following query is an example for UNION:
<programlisting>
<programlisting>
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNAME = 'Jones'
@ -1596,22 +1596,22 @@ UNION
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNAME = 'Adams';
</programlisting>
</programlisting>
gives the result:
<programlisting>
<screen>
SNO | SNAME | CITY
-----+-------+--------
2 | Jones | Paris
3 | Adams | Vienna
</programlisting>
</screen>
</para>
<para>
Here is an example for INTERSECT:
<programlisting>
<programlisting>
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO &gt; 1
@ -1619,15 +1619,15 @@ INTERSECT
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO &lt; 3;
</programlisting>
</programlisting>
gives the result:
<programlisting>
<screen>
SNO | SNAME | CITY
-----+-------+--------
2 | Jones | Paris
</programlisting>
</screen>
The only tuple returned by both parts of the query is the one having SNO=2.
</para>
@ -1635,7 +1635,7 @@ INTERSECT
<para>
Finally an example for EXCEPT:
<programlisting>
<programlisting>
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO &gt; 1
@ -1643,16 +1643,16 @@ EXCEPT
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO &gt; 3;
</programlisting>
</programlisting>
gives the result:
<programlisting>
<screen>
SNO | SNAME | CITY
-----+-------+--------
2 | Jones | Paris
3 | Adams | Vienna
</programlisting>
</screen>
</para>
</example>
</para>
@ -1675,12 +1675,12 @@ EXCEPT
one that creates a new relation (a new table). The syntax of the
<command>CREATE TABLE</command> command is:
<synopsis>
<synopsis>
CREATE TABLE <replaceable class="parameter">table_name</replaceable>
(<replaceable class="parameter">name_of_attr_1</replaceable> <replaceable class="parameter">type_of_attr_1</replaceable>
[, <replaceable class="parameter">name_of_attr_2</replaceable> <replaceable class="parameter">type_of_attr_2</replaceable>
[, ...]]);
</synopsis>
</synopsis>
<example>
<title id="table-create">Table Creation</title>
@ -1690,25 +1690,25 @@ CREATE TABLE <replaceable class="parameter">table_name</replaceable>
<xref linkend="supplier-fig" endterm="supplier-fig"> the
following <acronym>SQL</acronym> statements are used:
<programlisting>
<programlisting>
CREATE TABLE SUPPLIER
(SNO INTEGER,
SNAME VARCHAR(20),
CITY VARCHAR(20));
</programlisting>
</programlisting>
<programlisting>
<programlisting>
CREATE TABLE PART
(PNO INTEGER,
PNAME VARCHAR(20),
PRICE DECIMAL(4 , 2));
</programlisting>
</programlisting>
<programlisting>
<programlisting>
CREATE TABLE SELLS
(SNO INTEGER,
PNO INTEGER);
</programlisting>
</programlisting>
</para>
</example>
</para>
@ -1791,10 +1791,10 @@ CREATE TABLE SELLS
To create an index in <acronym>SQL</acronym>
the <command>CREATE INDEX</command> command is used. The syntax is:
<programlisting>
<programlisting>
CREATE INDEX <replaceable class="parameter">index_name</replaceable>
ON <replaceable class="parameter">table_name</replaceable> ( <replaceable class="parameter">name_of_attribute</replaceable> );
</programlisting>
</programlisting>
</para>
<para>
@ -1805,9 +1805,9 @@ CREATE INDEX <replaceable class="parameter">index_name</replaceable>
To create an index named I on attribute SNAME of relation SUPPLIER
we use the following statement:
<programlisting>
<programlisting>
CREATE INDEX I ON SUPPLIER (SNAME);
</programlisting>
</programlisting>
</para>
<para>
@ -1855,10 +1855,10 @@ CREATE INDEX I ON SUPPLIER (SNAME);
command is used to define a view. The syntax
is:
<programlisting>
<programlisting>
CREATE VIEW <replaceable class="parameter">view_name</replaceable>
AS <replaceable class="parameter">select_stmt</replaceable>
</programlisting>
</programlisting>
where <replaceable class="parameter">select_stmt</replaceable>
is a valid select statement as defined
@ -1874,14 +1874,14 @@ CREATE VIEW <replaceable class="parameter">view_name</replaceable>
the tables from
<xref linkend="supplier-fig" endterm="supplier-fig"> again):
<programlisting>
<programlisting>
CREATE VIEW London_Suppliers
AS SELECT S.SNAME, P.PNAME
FROM SUPPLIER S, PART P, SELLS SE
WHERE S.SNO = SE.SNO AND
P.PNO = SE.PNO AND
S.CITY = 'London';
</programlisting>
</programlisting>
</para>
<para>
@ -1889,18 +1889,18 @@ CREATE VIEW London_Suppliers
<classname>London_Suppliers</classname> as
if it were another base table:
<programlisting>
<programlisting>
SELECT * FROM London_Suppliers
WHERE PNAME = 'Screw';
</programlisting>
</programlisting>
which will return the following table:
<programlisting>
<screen>
SNAME | PNAME
-------+-------
Smith | Screw
</programlisting>
</screen>
</para>
<para>
@ -1922,34 +1922,34 @@ SELECT * FROM London_Suppliers
To destroy a table (including all tuples stored in that table) the
<command>DROP TABLE</command> command is used:
<programlisting>
<programlisting>
DROP TABLE <replaceable class="parameter">table_name</replaceable>;
</programlisting>
</programlisting>
</para>
<para>
To destroy the SUPPLIER table use the following statement:
<programlisting>
<programlisting>
DROP TABLE SUPPLIER;
</programlisting>
</programlisting>
</para>
<para>
The <command>DROP INDEX</command> command is used to destroy an index:
<programlisting>
<programlisting>
DROP INDEX <replaceable class="parameter">index_name</replaceable>;
</programlisting>
</programlisting>
</para>
<para>
Finally to destroy a given view use the command <command>DROP
VIEW</command>:
<programlisting>
<programlisting>
DROP VIEW <replaceable class="parameter">view_name</replaceable>;
</programlisting>
</programlisting>
</para>
</sect3>
</sect2>
@ -1966,11 +1966,11 @@ DROP VIEW <replaceable class="parameter">view_name</replaceable>;
with tuples using the command <command>INSERT INTO</command>.
The syntax is:
<programlisting>
<programlisting>
INSERT INTO <replaceable class="parameter">table_name</replaceable> (<replaceable class="parameter">name_of_attr_1</replaceable>
[, <replaceable class="parameter">name_of_attr_2</replaceable> [,...]])
VALUES (<replaceable class="parameter">val_attr_1</replaceable> [, <replaceable class="parameter">val_attr_2</replaceable> [, ...]]);
</programlisting>
</programlisting>
</para>
<para>
@ -1978,19 +1978,19 @@ INSERT INTO <replaceable class="parameter">table_name</replaceable> (<replaceabl
<xref linkend="supplier-fig" endterm="supplier-fig">) we use the
following statement:
<programlisting>
<programlisting>
INSERT INTO SUPPLIER (SNO, SNAME, CITY)
VALUES (1, 'Smith', 'London');
</programlisting>
</programlisting>
</para>
<para>
To insert the first tuple into the relation SELLS we use:
<programlisting>
<programlisting>
INSERT INTO SELLS (SNO, PNO)
VALUES (1, 1);
</programlisting>
</programlisting>
</para>
</sect3>
@ -2001,23 +2001,23 @@ INSERT INTO SELLS (SNO, PNO)
To change one or more attribute values of tuples in a relation the
<command>UPDATE</command> command is used. The syntax is:
<programlisting>
<programlisting>
UPDATE <replaceable class="parameter">table_name</replaceable>
SET <replaceable class="parameter">name_of_attr_1</replaceable> = <replaceable class="parameter">value_1</replaceable>
[, ... [, <replaceable class="parameter">name_of_attr_k</replaceable> = <replaceable class="parameter">value_k</replaceable>]]
WHERE <replaceable class="parameter">condition</replaceable>;
</programlisting>
</programlisting>
</para>
<para>
To change the value of attribute PRICE of the part 'Screw' in the
relation PART we use:
<programlisting>
<programlisting>
UPDATE PART
SET PRICE = 15
WHERE PNAME = 'Screw';
</programlisting>
</programlisting>
</para>
<para>
@ -2033,20 +2033,20 @@ UPDATE PART
To delete a tuple from a particular table use the command DELETE
FROM. The syntax is:
<programlisting>
<programlisting>
DELETE FROM <replaceable class="parameter">table_name</replaceable>
WHERE <replaceable class="parameter">condition</replaceable>;
</programlisting>
</programlisting>
</para>
<para>
To delete the supplier called 'Smith' of the table SUPPLIER the
following statement is used:
<programlisting>
<programlisting>
DELETE FROM SUPPLIER
WHERE SNAME = 'Smith';
</programlisting>
</programlisting>
</para>
</sect3>
</sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/sslinfo.sgml,v 1.4 2010/07/27 23:43:42 rhaas Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/sslinfo.sgml,v 1.5 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="sslinfo">
<title>sslinfo</title>
@ -147,7 +147,7 @@ ssl_client_dn_field(fieldname text) returns text
converted into ASN1 object identifiers using the OpenSSL object
database. The following values are acceptable:
</para>
<programlisting>
<literallayout class="monospaced">
commonName (alias CN)
surname (alias SN)
name
@ -169,7 +169,7 @@ x500UniqueIdentifier
pseudonym
role
emailAddress
</programlisting>
</literallayout>
<para>
All of these fields are optional, except <structfield>commonName</>.
It depends

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/doc/src/sgml/stylesheet.css,v 1.9 2009/08/26 21:18:29 petere Exp $ */
/* $PostgreSQL: pgsql/doc/src/sgml/stylesheet.css,v 1.10 2010/07/29 19:34:40 petere Exp $ */
/* color scheme similar to www.postgresql.org */
@ -85,7 +85,7 @@ DIV.EXAMPLE {
/* miscellaneous */
.SCREEN, .SYNOPSIS, .PROGRAMLISTING {
PRE.LITERALLAYOUT, .SCREEN, .SYNOPSIS, .PROGRAMLISTING {
margin-left: 4ex;
}

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/tablefunc.sgml,v 1.4 2007/12/06 04:12:10 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/tablefunc.sgml,v 1.5 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="tablefunc">
<title>tablefunc</title>
@ -94,9 +94,9 @@
<sect3>
<title><function>normal_rand</function></title>
<programlisting>
<synopsis>
normal_rand(int numvals, float8 mean, float8 stddev) returns setof float8
</programlisting>
</synopsis>
<para>
<function>normal_rand</> produces a set of normally distributed random
@ -115,7 +115,7 @@ normal_rand(int numvals, float8 mean, float8 stddev) returns setof float8
standard deviation of 3:
</para>
<programlisting>
<screen>
test=# SELECT * FROM normal_rand(1000, 5, 3);
normal_rand
----------------------
@ -131,22 +131,22 @@ test=# SELECT * FROM normal_rand(1000, 5, 3);
9.71308014517282
2.49639286969028
(1000 rows)
</programlisting>
</screen>
</sect3>
<sect3>
<title><function>crosstab(text)</function></title>
<programlisting>
<synopsis>
crosstab(text sql)
crosstab(text sql, int N)
</programlisting>
</synopsis>
<para>
The <function>crosstab</> function is used to produce <quote>pivot</>
displays, wherein data is listed across the page rather than down.
For example, we might have data like
<programlisting>
<programlisting>
row1 val11
row1 val12
row1 val13
@ -155,13 +155,13 @@ row2 val21
row2 val22
row2 val23
...
</programlisting>
</programlisting>
which we wish to display like
<programlisting>
<programlisting>
row1 val11 val12 val13 ...
row2 val21 val22 val23 ...
...
</programlisting>
</programlisting>
The <function>crosstab</> function takes a text parameter that is a SQL
query producing raw data formatted in the first way, and produces a table
formatted in the second way.
@ -180,8 +180,6 @@ row2 val21 val22 val23 ...
<para>
For example, the provided query might produce a set something like:
</para>
<programlisting>
row_name cat value
----------+-------+-------
@ -194,29 +192,25 @@ row2 val21 val22 val23 ...
row2 cat3 val7
row2 cat4 val8
</programlisting>
</para>
<para>
The <function>crosstab</> function is declared to return <type>setof
record</type>, so the actual names and types of the output columns must be
defined in the <literal>FROM</> clause of the calling <command>SELECT</>
statement, for example:
</para>
<programlisting>
SELECT * FROM crosstab('...') AS ct(row_name text, category_1 text, category_2 text);
</programlisting>
<para>
<programlisting>
SELECT * FROM crosstab('...') AS ct(row_name text, category_1 text, category_2 text);
</programlisting>
This example produces a set something like:
</para>
<programlisting>
<programlisting>
&lt;== value columns ==&gt;
row_name category_1 category_2
---------+------------+------------
row1 val1 val2
row2 val5 val6
</programlisting>
row_name category_1 category_2
----------+------------+------------
row1 val1 val2
row2 val5 val6
</programlisting>
</para>
<para>
The <literal>FROM</> clause must define the output as one
@ -250,9 +244,7 @@ row_name category_1 category_2
<para>
Here is a complete example:
</para>
<programlisting>
<programlisting>
CREATE TABLE ct(id SERIAL, rowid TEXT, attribute TEXT, value TEXT);
INSERT INTO ct(rowid, attribute, value) VALUES('test1','att1','val1');
INSERT INTO ct(rowid, attribute, value) VALUES('test1','att2','val2');
@ -276,7 +268,8 @@ AS ct(row_name text, category_1 text, category_2 text, category_3 text);
test1 | val2 | val3 |
test2 | val6 | val7 |
(2 rows)
</programlisting>
</programlisting>
</para>
<para>
You can avoid always having to write out a <literal>FROM</> clause to
@ -291,9 +284,9 @@ AS ct(row_name text, category_1 text, category_2 text, category_3 text);
<sect3>
<title><function>crosstab<replaceable>N</>(text)</function></title>
<programlisting>
<synopsis>
crosstab<replaceable>N</>(text sql)
</programlisting>
</synopsis>
<para>
The <function>crosstab<replaceable>N</></> functions are examples of how
@ -304,7 +297,7 @@ crosstab<replaceable>N</>(text sql)
<function>crosstab4</>, whose output rowtypes are defined as
</para>
<programlisting>
<programlisting>
CREATE TYPE tablefunc_crosstab_N AS (
row_name TEXT,
category_1 TEXT,
@ -314,7 +307,7 @@ CREATE TYPE tablefunc_crosstab_N AS (
.
category_N TEXT
);
</programlisting>
</programlisting>
<para>
Thus, these functions can be used directly when the input query produces
@ -327,23 +320,21 @@ CREATE TYPE tablefunc_crosstab_N AS (
<para>
For instance, the example given in the previous section would also
work as
</para>
<programlisting>
<programlisting>
SELECT *
FROM crosstab3(
'select rowid, attribute, value
from ct
where attribute = ''att2'' or attribute = ''att3''
order by 1,2');
</programlisting>
</programlisting>
</para>
<para>
These functions are provided mostly for illustration purposes. You
can create your own return types and functions based on the
underlying <function>crosstab()</> function. There are two ways
to do it:
</para>
<itemizedlist>
<listitem>
@ -355,52 +346,52 @@ FROM crosstab3(
<function>crosstab</> C function. For example, if your source data
produces row names that are <type>text</>, and values that are
<type>float8</>, and you want 5 value columns:
<programlisting>
CREATE TYPE my_crosstab_float8_5_cols AS (
my_row_name text,
my_category_1 float8,
my_category_2 float8,
my_category_3 float8,
my_category_4 float8,
my_category_5 float8
);
CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(text)
RETURNS setof my_crosstab_float8_5_cols
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
</programlisting>
</para>
<programlisting>
CREATE TYPE my_crosstab_float8_5_cols AS (
my_row_name text,
my_category_1 float8,
my_category_2 float8,
my_category_3 float8,
my_category_4 float8,
my_category_5 float8
);
CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(text)
RETURNS setof my_crosstab_float8_5_cols
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
</programlisting>
</listitem>
<listitem>
<para>
Use <literal>OUT</> parameters to define the return type implicitly.
The same example could also be done this way:
<programlisting>
CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(
IN text,
OUT my_row_name text,
OUT my_category_1 float8,
OUT my_category_2 float8,
OUT my_category_3 float8,
OUT my_category_4 float8,
OUT my_category_5 float8)
RETURNS setof record
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
</programlisting>
</para>
<programlisting>
CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(IN text,
OUT my_row_name text,
OUT my_category_1 float8,
OUT my_category_2 float8,
OUT my_category_3 float8,
OUT my_category_4 float8,
OUT my_category_5 float8)
RETURNS setof record
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
</programlisting>
</listitem>
</itemizedlist>
</para>
</sect3>
<sect3>
<title><function>crosstab(text, text)</function></title>
<programlisting>
<synopsis>
crosstab(text source_sql, text category_sql)
</programlisting>
</synopsis>
<para>
The main limitation of the single-parameter form of <function>crosstab</>
@ -432,8 +423,7 @@ crosstab(text source_sql, text category_sql)
<para>
For example, <parameter>source_sql</parameter> might produce a set
something like:
</para>
<programlisting>
<programlisting>
SELECT row_name, extra_col, cat, value FROM foo ORDER BY 1;
row_name extra_col cat value
@ -445,7 +435,8 @@ crosstab(text source_sql, text category_sql)
row2 extra2 cat2 val6
row2 extra2 cat3 val7
row2 extra2 cat4 val8
</programlisting>
</programlisting>
</para>
<para>
<parameter>category_sql</parameter> is a SQL statement that produces
@ -453,9 +444,8 @@ crosstab(text source_sql, text category_sql)
It must produce at least one row, or an error will be generated.
Also, it must not produce duplicate values, or an error will be
generated. <parameter>category_sql</parameter> might be something like:
</para>
<programlisting>
<programlisting>
SELECT DISTINCT cat FROM foo ORDER BY 1;
cat
-------
@ -463,32 +453,32 @@ SELECT DISTINCT cat FROM foo ORDER BY 1;
cat2
cat3
cat4
</programlisting>
</programlisting>
</para>
<para>
The <function>crosstab</> function is declared to return <type>setof
record</type>, so the actual names and types of the output columns must be
defined in the <literal>FROM</> clause of the calling <command>SELECT</>
statement, for example:
</para>
<programlisting>
SELECT * FROM crosstab('...', '...')
AS ct(row_name text, extra text, cat1 text, cat2 text, cat3 text, cat4 text);
</programlisting>
<programlisting>
SELECT * FROM crosstab('...', '...')
AS ct(row_name text, extra text, cat1 text, cat2 text, cat3 text, cat4 text);
</programlisting>
</para>
<para>
This will produce a result something like:
<programlisting>
&lt;== value columns ==&gt;
row_name extra cat1 cat2 cat3 cat4
---------+-------+------+------+------+------
row1 extra1 val1 val2 val4
row2 extra2 val5 val6 val7 val8
</programlisting>
</para>
<programlisting>
&lt;== value columns ==&gt;
row_name extra cat1 cat2 cat3 cat4
---------+-------+------+------+------+------
row1 extra1 val1 val2 val4
row2 extra2 val5 val6 val7 val8
</programlisting>
<para>
The <literal>FROM</> clause must define the proper number of output
columns of the proper data types. If there are <replaceable>N</>
@ -527,9 +517,7 @@ SELECT DISTINCT cat FROM foo ORDER BY 1;
<para>
Here are two complete examples:
</para>
<programlisting>
<programlisting>
create table sales(year int, month int, qty int);
insert into sales values(2007, 1, 1000);
insert into sales values(2007, 2, 1500);
@ -561,9 +549,9 @@ select * from crosstab(
2007 | 1000 | 1500 | | | | | 500 | | | | 1500 | 2000
2008 | 1000 | | | | | | | | | | |
(2 rows)
</programlisting>
</programlisting>
<programlisting>
<programlisting>
CREATE TABLE cth(rowid text, rowdt timestamp, attribute text, val text);
INSERT INTO cth VALUES('test1','01 March 2003','temperature','42');
INSERT INTO cth VALUES('test1','01 March 2003','test_result','PASS');
@ -592,7 +580,8 @@ AS
test1 | Sat Mar 01 00:00:00 2003 | 42 | PASS | | 2.6987
test2 | Sun Mar 02 00:00:00 2003 | 53 | FAIL | Sat Mar 01 00:00:00 2003 | 3.1234
(2 rows)
</programlisting>
</programlisting>
</para>
<para>
You can create predefined functions to avoid having to write out
@ -606,11 +595,11 @@ AS
<sect3>
<title><function>connectby</function></title>
<programlisting>
<synopsis>
connectby(text relname, text keyid_fld, text parent_keyid_fld
[, text orderby_fld ], text start_with, int max_depth
[, text branch_delim ])
</programlisting>
</synopsis>
<para>
The <function>connectby</> function produces a display of hierarchical
@ -675,10 +664,10 @@ connectby(text relname, text keyid_fld, text parent_keyid_fld
statement, for example:
</para>
<programlisting>
SELECT * FROM connectby('connectby_tree', 'keyid', 'parent_keyid', 'pos', 'row2', 0, '~')
AS t(keyid text, parent_keyid text, level int, branch text, pos int);
</programlisting>
<programlisting>
SELECT * FROM connectby('connectby_tree', 'keyid', 'parent_keyid', 'pos', 'row2', 0, '~')
AS t(keyid text, parent_keyid text, level int, branch text, pos int);
</programlisting>
<para>
The first two output columns are used for the current row's key and
@ -731,9 +720,7 @@ connectby(text relname, text keyid_fld, text parent_keyid_fld
<para>
Here is an example:
</para>
<programlisting>
<programlisting>
CREATE TABLE connectby_tree(keyid text, parent_keyid text, pos int);
INSERT INTO connectby_tree VALUES('row1',NULL, 0);
@ -797,7 +784,8 @@ SELECT * FROM connectby('connectby_tree', 'keyid', 'parent_keyid', 'pos', 'row2'
row6 | row4 | 2 | 5
row8 | row6 | 3 | 6
(6 rows)
</programlisting>
</programlisting>
</para>
</sect3>
</sect2>

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,7 @@
<listitem>
<para>
Each line represents pair: character_with_accent character_without_accent
<programlisting>
<programlisting>
&Agrave; A
&Aacute; A
&Acirc; A
@ -52,7 +52,7 @@
&Auml; A
&Aring; A
&AElig; A
</programlisting>
</programlisting>
</para>
</listitem>
</itemizedlist>
@ -133,15 +133,14 @@
<primary>unaccent</primary>
</indexterm>
<synopsis>
unaccent(<optional><replaceable class="PARAMETER">dictionary</replaceable>,
</optional> <replaceable class="PARAMETER">string</replaceable>)
returns <type>text</type>
</synopsis>
<synopsis>
unaccent(<optional><replaceable class="PARAMETER">dictionary</replaceable>, </optional> <replaceable class="PARAMETER">string</replaceable>)
returns <type>text</type>
</synopsis>
<para>
<programlisting>
SELECT unaccent('unaccent','Hôtel');
SELECT unaccent('unaccent', 'Hôtel');
SELECT unaccent('Hôtel');
</programlisting>
</para>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/uuid-ossp.sgml,v 1.2 2007/12/06 04:12:10 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/uuid-ossp.sgml,v 1.3 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="uuid-ossp">
<title>uuid-ossp</title>
@ -99,9 +99,9 @@
<para>
For example:
<programlisting>
SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
</programlisting>
<programlisting>
SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
</programlisting>
The name parameter will be MD5-hashed, so the cleartext cannot be
derived from the generated UUID.

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/vacuumlo.sgml,v 1.4 2009/02/26 16:02:37 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/vacuumlo.sgml,v 1.5 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="vacuumlo">
<title>vacuumlo</title>
@ -25,9 +25,9 @@
<sect2>
<title>Usage</title>
<synopsis>
<synopsis>
vacuumlo [options] database [database2 ... databaseN]
</synopsis>
</synopsis>
<para>
All databases named on the command line are processed. Available options

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/xaggr.sgml,v 1.40 2010/04/03 07:22:56 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/xaggr.sgml,v 1.41 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="xaggr">
<title>User-Defined Aggregates</title>
@ -169,7 +169,7 @@ SELECT attrelid::regclass, array_accum(atttypid::regtype)
aggregate transition or final function by calling
<function>AggCheckCallContext</>, for example:
<programlisting>
if (AggCheckCallContext(fcinfo, NULL))
if (AggCheckCallContext(fcinfo, NULL))
</programlisting>
One reason for checking this is that when it is true for a transition
function, the first input

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.151 2010/07/26 20:14:05 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.152 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="xfunc">
<title>User-Defined Functions</title>
@ -3359,22 +3359,22 @@ void RequestAddinLWLocks(int n)
<function>AddinShmemInitLock</> when connecting to and initializing
its allocation of shared memory, as shown here:
<programlisting>
static mystruct *ptr = NULL;
static mystruct *ptr = NULL;
if (!ptr)
if (!ptr)
{
bool found;
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
ptr = ShmemInitStruct("my struct name", size, &amp;found);
if (!found)
{
bool found;
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
ptr = ShmemInitStruct("my struct name", size, &amp;found);
if (!found)
{
initialize contents of shmem area;
acquire any requested LWLocks using:
ptr->mylockid = LWLockAssign();
}
LWLockRelease(AddinShmemInitLock);
initialize contents of shmem area;
acquire any requested LWLocks using:
ptr->mylockid = LWLockAssign();
}
LWLockRelease(AddinShmemInitLock);
}
</programlisting>
</para>
</sect2>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/xml2.sgml,v 1.8 2010/07/27 19:01:16 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/xml2.sgml,v 1.9 2010/07/29 19:34:40 petere Exp $ -->
<sect1 id="xml2">
<title>xml2</title>
@ -45,9 +45,9 @@
<tbody>
<row>
<entry>
<synopsis>
xml_is_well_formed(document) returns bool
</synopsis>
<synopsis>
xml_is_well_formed(document) returns bool
</synopsis>
</entry>
<entry>
<para>
@ -61,11 +61,11 @@
</row>
<row>
<entry>
<synopsis>
xpath_string(document,query) returns text
xpath_number(document,query) returns float4
xpath_bool(document,query) returns bool
</synopsis>
<synopsis>
xpath_string(document, query) returns text
xpath_number(document, query) returns float4
xpath_bool(document, query) returns bool
</synopsis>
</entry>
<entry>
<para>
@ -76,31 +76,29 @@
</row>
<row>
<entry>
<synopsis>
xpath_nodeset(document,query,toptag,itemtag) returns text
</synopsis>
<synopsis>
xpath_nodeset(document, query, toptag, itemtag) returns text
</synopsis>
</entry>
<entry>
<para>
This evaluates query on document and wraps the result in XML tags. If
the result is multivalued, the output will look like:
</para>
<literal>
&lt;toptag&gt;
&lt;itemtag&gt;Value 1 which could be an XML fragment&lt;/itemtag&gt;
&lt;itemtag&gt;Value 2....&lt;/itemtag&gt;
&lt;/toptag&gt;
</literal>
<para>
<synopsis>
&lt;toptag&gt;
&lt;itemtag&gt;Value 1 which could be an XML fragment&lt;/itemtag&gt;
&lt;itemtag&gt;Value 2....&lt;/itemtag&gt;
&lt;/toptag&gt;
</synopsis>
If either toptag or itemtag is an empty string, the relevant tag is omitted.
</para>
</entry>
</row>
<row>
<entry>
<synopsis>
xpath_nodeset(document,query) returns text
</synopsis>
<synopsis>
xpath_nodeset(document, query) returns text
</synopsis>
</entry>
<entry>
<para>
@ -110,9 +108,9 @@
</row>
<row>
<entry>
<synopsis>
xpath_nodeset(document,query,itemtag) returns text
</synopsis>
<synopsis>
xpath_nodeset(document, query, itemtag) returns text
</synopsis>
</entry>
<entry>
<para>
@ -122,9 +120,9 @@
</row>
<row>
<entry>
<synopsis>
xpath_list(document,query,separator) returns text
</synopsis>
<synopsis>
xpath_list(document, query, separator) returns text
</synopsis>
</entry>
<entry>
<para>
@ -136,9 +134,9 @@
</row>
<row>
<entry>
<synopsis>
xpath_list(document,query) returns text
</synopsis>
<synopsis>
xpath_list(document, query) returns text
</synopsis>
</entry>
<entry>
This is a wrapper for the above function that uses <literal>,</>
@ -153,9 +151,9 @@
<sect2>
<title><literal>xpath_table</literal></title>
<synopsis>
xpath_table(text key, text document, text relation, text xpaths, text criteria) returns setof record
</synopsis>
<synopsis>
xpath_table(text key, text document, text relation, text xpaths, text criteria) returns setof record
</synopsis>
<para>
<function>xpath_table</> is a table function that evaluates a set of XPath
@ -240,9 +238,7 @@
<para>
The function has to be used in a <literal>FROM</> expression, with an
<literal>AS</> clause to specify the output columns; for example
</para>
<programlisting>
<programlisting>
SELECT * FROM
xpath_table('article_id',
'article_xml',
@ -250,9 +246,7 @@ xpath_table('article_id',
'/article/author|/article/pages|/article/title',
'date_entered > ''2003-01-01'' ')
AS t(article_id integer, author text, page_count integer, title text);
</programlisting>
<para>
</programlisting>
The <literal>AS</> clause defines the names and types of the columns in the
output table. The first is the <quote>key</> field and the rest correspond
to the XPath queries.
@ -278,9 +272,7 @@ AS t(article_id integer, author text, page_count integer, title text);
columns by name or join them to other tables. The function produces a
virtual table with which you can perform any operation you wish (e.g.
aggregation, joining, sorting etc). So we could also have:
</para>
<programlisting>
<programlisting>
SELECT t.title, p.fullname, p.email
FROM xpath_table('article_id', 'article_xml', 'articles',
'/article/title|/article/author/@id',
@ -288,9 +280,7 @@ FROM xpath_table('article_id', 'article_xml', 'articles',
AS t(article_id integer, title text, author_id integer),
tblPeopleInfo AS p
WHERE t.author_id = p.person_id;
</programlisting>
<para>
</programlisting>
as a more complicated example. Of course, you could wrap all
of this in a view for convenience.
</para>
@ -314,60 +304,59 @@ WHERE t.author_id = p.person_id;
result will appear only on the first row of the result. The solution
to this is to use the key field as part of a join against a simpler
XPath query. As an example:
<programlisting>
CREATE TABLE test (
id int PRIMARY KEY,
xml text
);
INSERT INTO test VALUES (1, '&lt;doc num="C1"&gt;
&lt;line num="L1"&gt;&lt;a&gt;1&lt;/a&gt;&lt;b&gt;2&lt;/b&gt;&lt;c&gt;3&lt;/c&gt;&lt;/line&gt;
&lt;line num="L2"&gt;&lt;a&gt;11&lt;/a&gt;&lt;b&gt;22&lt;/b&gt;&lt;c&gt;33&lt;/c&gt;&lt;/line&gt;
&lt;/doc&gt;');
INSERT INTO test VALUES (2, '&lt;doc num="C2"&gt;
&lt;line num="L1"&gt;&lt;a&gt;111&lt;/a&gt;&lt;b&gt;222&lt;/b&gt;&lt;c&gt;333&lt;/c&gt;&lt;/line&gt;
&lt;line num="L2"&gt;&lt;a&gt;111&lt;/a&gt;&lt;b&gt;222&lt;/b&gt;&lt;c&gt;333&lt;/c&gt;&lt;/line&gt;
&lt;/doc&gt;');
SELECT * FROM
xpath_table('id','xml','test',
'/doc/@num|/doc/line/@num|/doc/line/a|/doc/line/b|/doc/line/c',
'true')
AS t(id int, doc_num varchar(10), line_num varchar(10), val1 int, val2 int, val3 int)
WHERE id = 1 ORDER BY doc_num, line_num
id | doc_num | line_num | val1 | val2 | val3
----+---------+----------+------+------+------
1 | C1 | L1 | 1 | 2 | 3
1 | | L2 | 11 | 22 | 33
</programlisting>
</para>
<programlisting>
CREATE TABLE test (
id int4 NOT NULL,
xml text,
CONSTRAINT pk PRIMARY KEY (id)
);
INSERT INTO test VALUES (1, '&lt;doc num="C1"&gt;
&lt;line num="L1"&gt;&lt;a&gt;1&lt;/a&gt;&lt;b&gt;2&lt;/b&gt;&lt;c&gt;3&lt;/c&gt;&lt;/line&gt;
&lt;line num="L2"&gt;&lt;a&gt;11&lt;/a&gt;&lt;b&gt;22&lt;/b&gt;&lt;c&gt;33&lt;/c&gt;&lt;/line&gt;
&lt;/doc&gt;');
INSERT INTO test VALUES (2, '&lt;doc num="C2"&gt;
&lt;line num="L1"&gt;&lt;a&gt;111&lt;/a&gt;&lt;b&gt;222&lt;/b&gt;&lt;c&gt;333&lt;/c&gt;&lt;/line&gt;
&lt;line num="L2"&gt;&lt;a&gt;111&lt;/a&gt;&lt;b&gt;222&lt;/b&gt;&lt;c&gt;333&lt;/c&gt;&lt;/line&gt;
&lt;/doc&gt;');
SELECT * FROM
xpath_table('id','xml','test',
'/doc/@num|/doc/line/@num|/doc/line/a|/doc/line/b|/doc/line/c',
'true')
AS t(id int4, doc_num varchar(10), line_num varchar(10), val1 int4, val2 int4, val3 int4)
WHERE id = 1 ORDER BY doc_num, line_num
id | doc_num | line_num | val1 | val2 | val3
----+---------+----------+------+------+------
1 | C1 | L1 | 1 | 2 | 3
1 | | L2 | 11 | 22 | 33
</programlisting>
<para>
To get doc_num on every line, the solution is to use two invocations
of xpath_table and join the results:
<programlisting>
SELECT t.*,i.doc_num FROM
xpath_table('id', 'xml', 'test',
'/doc/line/@num|/doc/line/a|/doc/line/b|/doc/line/c',
'true')
AS t(id int, line_num varchar(10), val1 int, val2 int, val3 int),
xpath_table('id', 'xml', 'test', '/doc/@num', 'true')
AS i(id int, doc_num varchar(10))
WHERE i.id=t.id AND i.id=1
ORDER BY doc_num, line_num;
id | line_num | val1 | val2 | val3 | doc_num
----+----------+------+------+------+---------
1 | L1 | 1 | 2 | 3 | C1
1 | L2 | 11 | 22 | 33 | C1
(2 rows)
</programlisting>
</para>
<programlisting>
SELECT t.*,i.doc_num FROM
xpath_table('id', 'xml', 'test',
'/doc/line/@num|/doc/line/a|/doc/line/b|/doc/line/c',
'true')
AS t(id int4, line_num varchar(10), val1 int4, val2 int4, val3 int4),
xpath_table('id', 'xml', 'test', '/doc/@num', 'true')
AS i(id int4, doc_num varchar(10))
WHERE i.id=t.id AND i.id=1
ORDER BY doc_num, line_num;
id | line_num | val1 | val2 | val3 | doc_num
----+----------+------+------+------+---------
1 | L1 | 1 | 2 | 3 | C1
1 | L2 | 11 | 22 | 33 | C1
(2 rows)
</programlisting>
</sect3>
</sect2>
@ -381,9 +370,9 @@ WHERE t.author_id = p.person_id;
<sect3>
<title><literal>xslt_process</literal></title>
<synopsis>
xslt_process(text document, text stylesheet, text paramlist) returns text
</synopsis>
<synopsis>
xslt_process(text document, text stylesheet, text paramlist) returns text
</synopsis>
<para>
This function applies the XSL stylesheet to the document and returns