Commit c918be6a authored by Tom Lane's avatar Tom Lane

Update description of numeric constants to match 7.3 reality.

Miscellaneous other copy-editing.
parent 2b2cf392
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.28 2002/06/11 15:32:32 thomas Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.29 2002/10/20 05:05:46 tgl Exp $
--> -->
<chapter id="tutorial-advanced"> <chapter id="tutorial-advanced">
...@@ -130,8 +130,8 @@ ERROR: &lt;unnamed&gt; referential integrity violation - key referenced from we ...@@ -130,8 +130,8 @@ ERROR: &lt;unnamed&gt; referential integrity violation - key referenced from we
<para> <para>
The behavior of foreign keys can be finely tuned to your The behavior of foreign keys can be finely tuned to your
application. We will not go beyond this simple example in this application. We will not go beyond this simple example in this
tutorial, but just refer you to the <citetitle>Reference tutorial, but just refer you to &cite-reference;
Manual</citetitle> for more information. Making correct use of for more information. Making correct use of
foreign keys will definitely improve the quality of your database foreign keys will definitely improve the quality of your database
applications, so you are strongly encouraged to learn about them. applications, so you are strongly encouraged to learn about them.
</para> </para>
...@@ -394,9 +394,8 @@ SELECT name, altitude ...@@ -394,9 +394,8 @@ SELECT name, altitude
<productname>PostgreSQL</productname> has many features not <productname>PostgreSQL</productname> has many features not
touched upon in this tutorial introduction, which has been touched upon in this tutorial introduction, which has been
oriented toward newer users of <acronym>SQL</acronym>. These oriented toward newer users of <acronym>SQL</acronym>. These
features are discussed in more detail in both the features are discussed in more detail in both &cite-user;
<citetitle>User's Guide</citetitle> and the and &cite-programmer;.
<citetitle>Programmer's Guide</citetitle>.
</para> </para>
<para> <para>
......
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ddl.sgml,v 1.5 2002/09/21 18:32:52 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/ddl.sgml,v 1.6 2002/10/20 05:05:46 tgl Exp $ -->
<chapter id="ddl"> <chapter id="ddl">
<title>Data Definition</title> <title>Data Definition</title>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
explaining how tables are created and modified and what features are explaining how tables are created and modified and what features are
available to control what data is stored in the tables. available to control what data is stored in the tables.
Subsequently, we discuss how tables can be organized into Subsequently, we discuss how tables can be organized into
namespaces, and how privileges can be assigned to tables. Finally, schemas, and how privileges can be assigned to tables. Finally,
we will briefly look at other features that affect the data storage, we will briefly look at other features that affect the data storage,
such as views, functions, and triggers. Detailed information on such as views, functions, and triggers. Detailed information on
these topics is found in &cite-programmer;. these topics is found in &cite-programmer;.
...@@ -78,7 +78,7 @@ CREATE TABLE my_first_table ( ...@@ -78,7 +78,7 @@ CREATE TABLE my_first_table (
<literal>second_column</literal> and the type <type>integer</type>. <literal>second_column</literal> and the type <type>integer</type>.
The table and column names follow the identifier syntax explained The table and column names follow the identifier syntax explained
in <xref linkend="sql-syntax-identifiers">. The type names are in <xref linkend="sql-syntax-identifiers">. The type names are
also identifiers, but there are some exceptions. Note that the usually also identifiers, but there are some exceptions. Note that the
column list is comma-separated and surrounded by parentheses. column list is comma-separated and surrounded by parentheses.
</para> </para>
...@@ -101,7 +101,7 @@ CREATE TABLE products ( ...@@ -101,7 +101,7 @@ CREATE TABLE products (
<tip> <tip>
<para> <para>
When you create many interrelated tables it is wise to choose a When you create many interrelated tables it is wise to choose a
consistent naming patter for the tables and columns. For consistent naming pattern for the tables and columns. For
instance, there is a choice of using singular or plural nouns for instance, there is a choice of using singular or plural nouns for
table names, both of which are favored by some theorist or other. table names, both of which are favored by some theorist or other.
</para> </para>
...@@ -287,7 +287,7 @@ CREATE TABLE products ( ...@@ -287,7 +287,7 @@ CREATE TABLE products (
</para> </para>
<para> <para>
The default value may be a scalar expression, which well be The default value may be a scalar expression, which will be
evaluated whenever the default value is inserted evaluated whenever the default value is inserted
(<emphasis>not</emphasis> when the table is created). (<emphasis>not</emphasis> when the table is created).
</para> </para>
...@@ -618,7 +618,8 @@ CREATE TABLE example ( ...@@ -618,7 +618,8 @@ CREATE TABLE example (
<para> <para>
A foreign key constraint specifies that the values in a column (or A foreign key constraint specifies that the values in a column (or
a group of columns) must match the values in some other column. a group of columns) must match the values appearing in some row
of another table.
We say this maintains the <firstterm>referential We say this maintains the <firstterm>referential
integrity</firstterm> between two related tables. integrity</firstterm> between two related tables.
</para> </para>
...@@ -758,7 +759,7 @@ CREATE TABLE order_items ( ...@@ -758,7 +759,7 @@ CREATE TABLE order_items (
<para> <para>
Restricting and cascading deletes are the two most common options. Restricting and cascading deletes are the two most common options.
<literal>RESTRICT</literal> can also be written as <literal>NO <literal>RESTRICT</literal> can also be written as <literal>NO
ACTON</literal> and it's also the default if you don't specify ACTION</literal> and it's also the default if you don't specify
anything. There are two other options for what should happen with anything. There are two other options for what should happen with
the foreign key columns when a primary key is deleted: the foreign key columns when a primary key is deleted:
<literal>SET NULL</literal> and <literal>SET DEFAULT</literal>. <literal>SET NULL</literal> and <literal>SET DEFAULT</literal>.
...@@ -981,7 +982,7 @@ SET SQL_Inheritance TO OFF; ...@@ -981,7 +982,7 @@ SET SQL_Inheritance TO OFF;
<para>Add columns,</para> <para>Add columns,</para>
</listitem> </listitem>
<listitem> <listitem>
<para>Remove a column,</para> <para>Remove columns,</para>
</listitem> </listitem>
<listitem> <listitem>
<para>Add constraints,</para> <para>Add constraints,</para>
...@@ -993,10 +994,10 @@ SET SQL_Inheritance TO OFF; ...@@ -993,10 +994,10 @@ SET SQL_Inheritance TO OFF;
<para>Change default values,</para> <para>Change default values,</para>
</listitem> </listitem>
<listitem> <listitem>
<para>Rename a column,</para> <para>Rename columns,</para>
</listitem> </listitem>
<listitem> <listitem>
<para>Rename the table.</para> <para>Rename tables.</para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
...@@ -1270,7 +1271,7 @@ REVOKE ALL ON accounts FROM PUBLIC; ...@@ -1270,7 +1271,7 @@ REVOKE ALL ON accounts FROM PUBLIC;
</itemizedlist> </itemizedlist>
Schemas are analogous to directories at the operating system level, Schemas are analogous to directories at the operating system level,
but schemas cannot be nested. except that schemas cannot be nested.
</para> </para>
<sect2 id="ddl-schemas-create"> <sect2 id="ddl-schemas-create">
...@@ -1341,7 +1342,7 @@ DROP SCHEMA myschema CASCADE; ...@@ -1341,7 +1342,7 @@ DROP SCHEMA myschema CASCADE;
(since this is one of the ways to restrict the activities of your (since this is one of the ways to restrict the activities of your
users to well-defined namespaces). The syntax for that is: users to well-defined namespaces). The syntax for that is:
<programlisting> <programlisting>
CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATON <replaceable>username</replaceable>; CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATION <replaceable>username</replaceable>;
</programlisting> </programlisting>
You can even omit the schema name, in which case the schema name You can even omit the schema name, in which case the schema name
will be the same as the user name. See <xref will be the same as the user name. See <xref
...@@ -1359,9 +1360,9 @@ CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATON <replaceable>us ...@@ -1359,9 +1360,9 @@ CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATON <replaceable>us
<para> <para>
In the previous sections we created tables without specifying any In the previous sections we created tables without specifying any
schema names. Those tables (and other objects) are automatically schema names. By default, such tables (and other objects) are
put into a schema named <quote>public</quote>. Every new database automatically put into a schema named <quote>public</quote>. Every new
contains such a schema. Thus, the following are equivalent: database contains such a schema. Thus, the following are equivalent:
<programlisting> <programlisting>
CREATE TABLE products ( ... ); CREATE TABLE products ( ... );
</programlisting> </programlisting>
...@@ -1550,7 +1551,7 @@ REVOKE CREATE ON public FROM PUBLIC; ...@@ -1550,7 +1551,7 @@ REVOKE CREATE ON public FROM PUBLIC;
<para> <para>
Schemas can be used to organize your data in many ways. There are Schemas can be used to organize your data in many ways. There are
a few usage patterns are recommended and are easily supported by a few usage patterns that are recommended and are easily supported by
the default configuration: the default configuration:
<itemizedlist> <itemizedlist>
<listitem> <listitem>
...@@ -1558,7 +1559,7 @@ REVOKE CREATE ON public FROM PUBLIC; ...@@ -1558,7 +1559,7 @@ REVOKE CREATE ON public FROM PUBLIC;
If you do not create any schemas then all users access the If you do not create any schemas then all users access the
public schema implicitly. This simulates the situation where public schema implicitly. This simulates the situation where
schemas are not available at all. This setup is mainly schemas are not available at all. This setup is mainly
recommended when there is only a single user or few cooperating recommended when there is only a single user or a few cooperating
users in a database. This setup also allows smooth transition users in a database. This setup also allows smooth transition
from the non-schema-aware world. from the non-schema-aware world.
</para> </para>
...@@ -1586,7 +1587,7 @@ REVOKE CREATE ON public FROM PUBLIC; ...@@ -1586,7 +1587,7 @@ REVOKE CREATE ON public FROM PUBLIC;
additional functions provided by third parties, etc.), put them additional functions provided by third parties, etc.), put them
into separate schemas. Remember to grant appropriate into separate schemas. Remember to grant appropriate
privileges to allow the other users to access them. Users can privileges to allow the other users to access them. Users can
then refer to these additional object by qualifying the names then refer to these additional objects by qualifying the names
with a schema name, or they can put the additional schemas into with a schema name, or they can put the additional schemas into
their path, as they choose. their path, as they choose.
</para> </para>
...@@ -1690,9 +1691,10 @@ ERROR: Cannot drop table products because other objects depend on it ...@@ -1690,9 +1691,10 @@ ERROR: Cannot drop table products because other objects depend on it
<screen> <screen>
DROP TABLE products CASCADE; DROP TABLE products CASCADE;
</screen> </screen>
and all the dependent objects will be removed. Actually, this and all the dependent objects will be removed. In this case, it
doesn't remove the orders table, it only removes the foreign key doesn't remove the orders table, it only removes the foreign key
constraint. constraint. (If you want to check what DROP ... CASCADE will do,
run DROP without CASCADE and read the NOTICEs.)
</para> </para>
<para> <para>
...@@ -1709,7 +1711,8 @@ DROP TABLE products CASCADE; ...@@ -1709,7 +1711,8 @@ DROP TABLE products CASCADE;
According to the SQL standard, specifying either According to the SQL standard, specifying either
<literal>RESTRICT</literal> or <literal>CASCADE</literal> is <literal>RESTRICT</literal> or <literal>CASCADE</literal> is
required. No database system actually implements it that way, but required. No database system actually implements it that way, but
the defaults might be different. whether the default behavior is <literal>RESTRICT</literal> or
<literal>CASCADE</literal> varies across systems.
</para> </para>
</note> </note>
...@@ -1718,7 +1721,8 @@ DROP TABLE products CASCADE; ...@@ -1718,7 +1721,8 @@ DROP TABLE products CASCADE;
Foreign key constraint dependencies and serial column dependencies Foreign key constraint dependencies and serial column dependencies
from <productname>PostgreSQL</productname> versions prior to 7.3 from <productname>PostgreSQL</productname> versions prior to 7.3
are <emphasis>not</emphasis> maintained or created during the are <emphasis>not</emphasis> maintained or created during the
upgrade process. All other dependency types survive the upgrade. upgrade process. All other dependency types will be properly
created during an upgrade.
</para> </para>
</note> </note>
</sect1> </sect1>
......
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/dml.sgml,v 1.1 2002/08/05 19:44:57 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/dml.sgml,v 1.2 2002/10/20 05:05:46 tgl Exp $ -->
<chapter id="dml"> <chapter id="dml">
<title>Data Manipulation</title> <title>Data Manipulation</title>
...@@ -119,8 +119,8 @@ INSERT INTO products DEFAULT VALUES; ...@@ -119,8 +119,8 @@ INSERT INTO products DEFAULT VALUES;
necessarily possible to directly specify which row to update. necessarily possible to directly specify which row to update.
Instead, you specify which conditions a row must meet in order to Instead, you specify which conditions a row must meet in order to
be updated. Only if you have a primary key in the table (no matter be updated. Only if you have a primary key in the table (no matter
whether you declared it or not) you can address rows individually whether you declared it or not) can you reliably address individual rows,
by choosing a condition that matches the primary key only. by choosing a condition that matches the primary key.
Graphical database access tools rely on this fact to allow you to Graphical database access tools rely on this fact to allow you to
update rows individually. update rows individually.
</para> </para>
...@@ -195,5 +195,13 @@ UPDATE mytable SET a = 5, b = 3, c = 1 WHERE a > 0; ...@@ -195,5 +195,13 @@ UPDATE mytable SET a = 5, b = 3, c = 1 WHERE a > 0;
DELETE FROM products WHERE price = 10; DELETE FROM products WHERE price = 10;
</programlisting> </programlisting>
</para> </para>
<para>
If you simply write
<programlisting>
DELETE FROM products;
</programlisting>
then all rows in the table will be deleted! Caveat programmer.
</para>
</sect1> </sect1>
</chapter> </chapter>
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/queries.sgml,v 1.17 2002/09/20 18:39:41 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/queries.sgml,v 1.18 2002/10/20 05:05:46 tgl Exp $ -->
<chapter id="queries"> <chapter id="queries">
<title>Queries</title> <title>Queries</title>
...@@ -35,13 +35,12 @@ SELECT * FROM table1; ...@@ -35,13 +35,12 @@ SELECT * FROM table1;
<literal>table1</literal>. (The method of retrieval depends on the <literal>table1</literal>. (The method of retrieval depends on the
client application. For example, the client application. For example, the
<application>psql</application> program will display an ASCII-art <application>psql</application> program will display an ASCII-art
table on the screen, client libraries will offer functions to table on the screen, while client libraries will offer functions to
retrieve individual rows and columns.) The select list retrieve individual rows and columns.) The select list
specification <literal>*</literal> means all columns that the table specification <literal>*</literal> means all columns that the table
expression happens to provide. A select list can also select a expression happens to provide. A select list can also select a
subset of the available columns or even make calculations on the subset of the available columns or make calculations using the
columns before retrieving them; see <xref columns. For example, if
linkend="queries-select-lists">. For example, if
<literal>table1</literal> has columns named <literal>a</>, <literal>table1</literal> has columns named <literal>a</>,
<literal>b</>, and <literal>c</> (and perhaps others) you can make <literal>b</>, and <literal>c</> (and perhaps others) you can make
the following query: the following query:
...@@ -50,6 +49,7 @@ SELECT a, b + c FROM table1; ...@@ -50,6 +49,7 @@ SELECT a, b + c FROM table1;
</programlisting> </programlisting>
(assuming that <literal>b</> and <literal>c</> are of a numerical (assuming that <literal>b</> and <literal>c</> are of a numerical
data type). data type).
See <xref linkend="queries-select-lists"> for more details.
</para> </para>
<para> <para>
...@@ -62,7 +62,7 @@ SELECT a, b + c FROM table1; ...@@ -62,7 +62,7 @@ SELECT a, b + c FROM table1;
SELECT 3 * 4; SELECT 3 * 4;
</programlisting> </programlisting>
This is more useful if the expressions in the select list return This is more useful if the expressions in the select list return
varying results. For example, you could call a function this way. varying results. For example, you could call a function this way:
<programlisting> <programlisting>
SELECT random(); SELECT random();
</programlisting> </programlisting>
...@@ -266,7 +266,7 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r ...@@ -266,7 +266,7 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
<para> <para>
First, an inner join is performed. Then, for each row in First, an inner join is performed. Then, for each row in
T1 that does not satisfy the join condition with any row in T1 that does not satisfy the join condition with any row in
T2, a joined row is returned with null values in columns of T2, a joined row is added with null values in columns of
T2. Thus, the joined table unconditionally has at least T2. Thus, the joined table unconditionally has at least
one row for each row in T1. one row for each row in T1.
</para> </para>
...@@ -280,7 +280,7 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r ...@@ -280,7 +280,7 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
<para> <para>
First, an inner join is performed. Then, for each row in First, an inner join is performed. Then, for each row in
T2 that does not satisfy the join condition with any row in T2 that does not satisfy the join condition with any row in
T1, a joined row is returned with null values in columns of T1, a joined row is added with null values in columns of
T1. This is the converse of a left join: the result table T1. This is the converse of a left join: the result table
will unconditionally have a row for each row in T2. will unconditionally have a row for each row in T2.
</para> </para>
...@@ -294,10 +294,10 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r ...@@ -294,10 +294,10 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
<para> <para>
First, an inner join is performed. Then, for each row in First, an inner join is performed. Then, for each row in
T1 that does not satisfy the join condition with any row in T1 that does not satisfy the join condition with any row in
T2, a joined row is returned with null values in columns of T2, a joined row is added with null values in columns of
T2. Also, for each row of T2 that does not satisfy the T2. Also, for each row of T2 that does not satisfy the
join condition with any row in T1, a joined row with null join condition with any row in T1, a joined row with null
values in the columns of T1 is returned. values in the columns of T1 is added.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -602,7 +602,7 @@ FROM a NATURAL JOIN b WHERE b.val &gt; 5 ...@@ -602,7 +602,7 @@ FROM a NATURAL JOIN b WHERE b.val &gt; 5
<literal>JOIN</> syntax in the <literal>FROM</> clause is <literal>JOIN</> syntax in the <literal>FROM</> clause is
probably not as portable to other SQL database products. For probably not as portable to other SQL database products. For
outer joins there is no choice in any case: they must be done in outer joins there is no choice in any case: they must be done in
the <literal>FROM</> clause. A <literal>ON</>/<literal>USING</> the <literal>FROM</> clause. An <literal>ON</>/<literal>USING</>
clause of an outer join is <emphasis>not</> equivalent to a clause of an outer join is <emphasis>not</> equivalent to a
<literal>WHERE</> condition, because it determines the addition <literal>WHERE</> condition, because it determines the addition
of rows (for unmatched input rows) as well as the removal of rows of rows (for unmatched input rows) as well as the removal of rows
...@@ -692,11 +692,11 @@ SELECT <replaceable>select_list</replaceable> ...@@ -692,11 +692,11 @@ SELECT <replaceable>select_list</replaceable>
<para> <para>
In the second query, we could not have written <literal>SELECT * In the second query, we could not have written <literal>SELECT *
FROM test1 GROUP BY x;</literal>, because there is no single value FROM test1 GROUP BY x</literal>, because there is no single value
for the column <literal>y</> that could be associated with each for the column <literal>y</> that could be associated with each
group. In general, if a table is grouped, columns that are not group. In general, if a table is grouped, columns that are not
used in the grouping cannot be referenced except in aggregate used in the grouping cannot be referenced except in aggregate
expressions, for example: expressions. An example with aggregate expressions is:
<screen> <screen>
<prompt>=></> <userinput>SELECT x, sum(y) FROM test1 GROUP BY x;</> <prompt>=></> <userinput>SELECT x, sum(y) FROM test1 GROUP BY x;</>
x | sum x | sum
...@@ -717,25 +717,25 @@ SELECT <replaceable>select_list</replaceable> ...@@ -717,25 +717,25 @@ SELECT <replaceable>select_list</replaceable>
they have a known constant value per group. they have a known constant value per group.
</para> </para>
<note> <tip>
<para> <para>
Grouping without aggregate expressions effectively calculates the Grouping without aggregate expressions effectively calculates the
set of distinct values in a column. This can also be achieved set of distinct values in a column. This can also be achieved
using the <literal>DISTINCT</> clause (see <xref using the <literal>DISTINCT</> clause (see <xref
linkend="queries-distinct">). linkend="queries-distinct">).
</para> </para>
</note> </tip>
<para> <para>
Here is another example: A <function>sum(sales)</function> on a Here is another example: <function>sum(sales)</function> on a
table grouped by product code gives the total sales for each table grouped by product code gives the total sales for each
product, not the total sales on all products. product, not the total sales on all products.
<programlisting> <programlisting>
SELECT product_id, p.name, (sum(s.units) * p.price) AS sales SELECT product_id, p.name, (sum(s.units) * p.price) AS sales
FROM products p LEFT JOIN sales s USING (product_id) FROM products p LEFT JOIN sales s USING (product_id)
GROUP BY pid, p.name, p.price; GROUP BY product_id, p.name, p.price;
</programlisting> </programlisting>
In this example, the columns <literal>pid</literal>, In this example, the columns <literal>product_id</literal>,
<literal>p.name</literal>, and <literal>p.price</literal> must be <literal>p.name</literal>, and <literal>p.price</literal> must be
in the <literal>GROUP BY</> clause since they are referenced in in the <literal>GROUP BY</> clause since they are referenced in
the query select list. (Depending on how exactly the products the query select list. (Depending on how exactly the products
...@@ -767,7 +767,7 @@ SELECT product_id, p.name, (sum(s.units) * p.price) AS sales ...@@ -767,7 +767,7 @@ SELECT product_id, p.name, (sum(s.units) * p.price) AS sales
SELECT <replaceable>select_list</replaceable> FROM ... <optional>WHERE ...</optional> GROUP BY ... HAVING <replaceable>boolean_expression</replaceable> SELECT <replaceable>select_list</replaceable> FROM ... <optional>WHERE ...</optional> GROUP BY ... HAVING <replaceable>boolean_expression</replaceable>
</synopsis> </synopsis>
Expressions in the <literal>HAVING</> clause can refer both to Expressions in the <literal>HAVING</> clause can refer both to
grouped expressions and to ungrouped expression (which necessarily grouped expressions and to ungrouped expressions (which necessarily
involve an aggregate function). involve an aggregate function).
</para> </para>
...@@ -794,7 +794,7 @@ SELECT <replaceable>select_list</replaceable> FROM ... <optional>WHERE ...</opti ...@@ -794,7 +794,7 @@ SELECT <replaceable>select_list</replaceable> FROM ... <optional>WHERE ...</opti
Again, a more realistic example: Again, a more realistic example:
<programlisting> <programlisting>
SELECT product_id, p.name, (sum(s.units) * (p.price - p.cost)) AS profit SELECT product_id, p.name, (sum(s.units) * (p.price - p.cost)) AS profit
FROM products p LEFT JOIN sales s USING (pid) FROM products p LEFT JOIN sales s USING (product_id)
WHERE s.date > CURRENT_DATE - INTERVAL '4 weeks' WHERE s.date > CURRENT_DATE - INTERVAL '4 weeks'
GROUP BY product_id, p.name, p.price, p.cost GROUP BY product_id, p.name, p.price, p.cost
HAVING sum(p.price * s.units) > 5000; HAVING sum(p.price * s.units) > 5000;
...@@ -1093,7 +1093,7 @@ SELECT a AS b FROM table1 ORDER BY a; ...@@ -1093,7 +1093,7 @@ SELECT a AS b FROM table1 ORDER BY a;
<para> <para>
If more than one sort column is specified, the later entries are If more than one sort column is specified, the later entries are
used to sort rows that are equal under the order imposed by the used to sort rows that are equal under the order imposed by the
earlier sort specifications. earlier sort columns.
</para> </para>
</sect1> </sect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/query.sgml,v 1.25 2002/01/20 22:19:56 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/query.sgml,v 1.26 2002/10/20 05:05:46 tgl Exp $
--> -->
<chapter id="tutorial-sql"> <chapter id="tutorial-sql">
...@@ -205,7 +205,7 @@ INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27'); ...@@ -205,7 +205,7 @@ INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');
Constants that are not simple numeric values usually must be Constants that are not simple numeric values usually must be
surrounded by single quotes (<literal>'</>), as in the example. surrounded by single quotes (<literal>'</>), as in the example.
The The
<type>date</type> column is actually quite flexible in what it <type>date</type> type is actually quite flexible in what it
accepts, but for this tutorial we will stick to the unambiguous accepts, but for this tutorial we will stick to the unambiguous
format shown here. format shown here.
</para> </para>
...@@ -259,8 +259,7 @@ COPY weather FROM '/home/user/weather.txt'; ...@@ -259,8 +259,7 @@ COPY weather FROM '/home/user/weather.txt';
where the file name for the source file must be available to the where the file name for the source file must be available to the
backend server machine, not the client, since the backend server backend server machine, not the client, since the backend server
reads the file directly. You can read more about the reads the file directly. You can read more about the
<command>COPY</command> command in the <citetitle>Reference <command>COPY</command> command in &cite-reference;.
Manual</citetitle>.
</para> </para>
</sect1> </sect1>
...@@ -341,10 +340,7 @@ SELECT * FROM weather ...@@ -341,10 +340,7 @@ SELECT * FROM weather
<indexterm><primary>duplicate</primary></indexterm> <indexterm><primary>duplicate</primary></indexterm>
As a final note, you can request that the results of a select can As a final note, you can request that the results of a select can
be returned in sorted order or with duplicate rows removed. (Just be returned in sorted order or with duplicate rows removed:
to make sure the following won't confuse you,
<literal>DISTINCT</literal> and <literal>ORDER BY</literal> can be
used separately.)
<programlisting> <programlisting>
SELECT DISTINCT city SELECT DISTINCT city
...@@ -359,6 +355,9 @@ SELECT DISTINCT city ...@@ -359,6 +355,9 @@ SELECT DISTINCT city
San Francisco San Francisco
(2 rows) (2 rows)
</screen> </screen>
<literal>DISTINCT</literal> and <literal>ORDER BY</literal> can be
used separately, of course.
</para> </para>
</sect1> </sect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.24 2002/08/13 20:40:43 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.25 2002/10/20 05:05:46 tgl Exp $
--> -->
<chapter id="tutorial-start"> <chapter id="tutorial-start">
...@@ -31,8 +31,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.24 2002/08/13 20:40:43 momji ...@@ -31,8 +31,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.24 2002/08/13 20:40:43 momji
<para> <para>
If you are installing <productname>PostgreSQL</productname> If you are installing <productname>PostgreSQL</productname>
yourself, then refer to the <citetitle>Administrator's yourself, then refer to &cite-admin;
Guide</citetitle> for instructions on installation, and return to for instructions on installation, and return to
this guide when the installation is complete. Be sure to follow this guide when the installation is complete. Be sure to follow
closely the section about setting up the appropriate environment closely the section about setting up the appropriate environment
variables. variables.
...@@ -87,7 +87,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.24 2002/08/13 20:40:43 momji ...@@ -87,7 +87,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.24 2002/08/13 20:40:43 momji
<para> <para>
The user's client (frontend) application that wants to perform The user's client (frontend) application that wants to perform
database operations. Client applications can be very diverse database operations. Client applications can be very diverse
in nature: They could be a text-oriented tool, a graphical in nature: a client could be a text-oriented tool, a graphical
application, a web server that accesses the database to application, a web server that accesses the database to
display web pages, or a specialized database maintenance tool. display web pages, or a specialized database maintenance tool.
Some client applications are supplied with the Some client applications are supplied with the
...@@ -292,8 +292,7 @@ createdb: database creation failed ...@@ -292,8 +292,7 @@ createdb: database creation failed
<para> <para>
Writing a custom application, using one of the several Writing a custom application, using one of the several
available language bindings. These possibilities are discussed available language bindings. These possibilities are discussed
further in <citetitle>The PostgreSQL Programmer's further in &cite-programmer;.
Guide</citetitle>.
</para> </para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
...@@ -353,13 +352,13 @@ mydb=# ...@@ -353,13 +352,13 @@ mydb=#
<prompt>mydb=&gt;</prompt> <userinput>SELECT version();</userinput> <prompt>mydb=&gt;</prompt> <userinput>SELECT version();</userinput>
version version
---------------------------------------------------------------- ----------------------------------------------------------------
PostgreSQL 7.2devel on i586-pc-linux-gnu, compiled by GCC 2.96 PostgreSQL 7.3devel on i586-pc-linux-gnu, compiled by GCC 2.96
(1 row) (1 row)
<prompt>mydb=&gt;</prompt> <userinput>SELECT current_date;</userinput> <prompt>mydb=&gt;</prompt> <userinput>SELECT current_date;</userinput>
date date
------------ ------------
2001-08-31 2002-08-31
(1 row) (1 row)
<prompt>mydb=&gt;</prompt> <userinput>SELECT 2 + 2;</userinput> <prompt>mydb=&gt;</prompt> <userinput>SELECT 2 + 2;</userinput>
...@@ -391,8 +390,8 @@ mydb=# ...@@ -391,8 +390,8 @@ mydb=#
and <command>psql</command> will quit and return you to your and <command>psql</command> will quit and return you to your
command shell. (For more internal commands, type command shell. (For more internal commands, type
<literal>\?</literal> at the <command>psql</command> prompt.) The <literal>\?</literal> at the <command>psql</command> prompt.) The
full capabilities of <command>psql</command> are documented in the full capabilities of <command>psql</command> are documented in
<citetitle>Reference Manual</citetitle>. If <productname>PostgreSQL</> is &cite-reference;. If <productname>PostgreSQL</> is
installed correctly you can also type <literal>man psql</literal> installed correctly you can also type <literal>man psql</literal>
at the operating system shell prompt to see the documentation. In at the operating system shell prompt to see the documentation. In
this tutorial we will not use these features explicitly, but you this tutorial we will not use these features explicitly, but you
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.70 2002/09/21 18:32:54 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.71 2002/10/20 05:05:46 tgl Exp $
--> -->
<chapter id="sql-syntax"> <chapter id="sql-syntax">
...@@ -73,8 +73,8 @@ INSERT INTO MY_TABLE VALUES (3, 'hi there'); ...@@ -73,8 +73,8 @@ INSERT INTO MY_TABLE VALUES (3, 'hi there');
a <token>SET</token> token to appear in a certain position, and a <token>SET</token> token to appear in a certain position, and
this particular variation of <command>INSERT</command> also this particular variation of <command>INSERT</command> also
requires a <token>VALUES</token> in order to be complete. The requires a <token>VALUES</token> in order to be complete. The
precise syntax rules for each command are described in the precise syntax rules for each command are described in
<citetitle>Reference Manual</citetitle>. &cite-reference;.
</para> </para>
<sect2 id="sql-syntax-identifiers"> <sect2 id="sql-syntax-identifiers">
...@@ -206,9 +206,9 @@ UPDATE "my_table" SET "a" = 5; ...@@ -206,9 +206,9 @@ UPDATE "my_table" SET "a" = 5;
</indexterm> </indexterm>
<para> <para>
There are four kinds of <firstterm>implicitly-typed There are three kinds of <firstterm>implicitly-typed
constants</firstterm> in <productname>PostgreSQL</productname>: constants</firstterm> in <productname>PostgreSQL</productname>:
strings, bit strings, integers, and floating-point numbers. strings, bit strings, and numbers.
Constants can also be specified with explicit types, which can Constants can also be specified with explicit types, which can
enable more accurate representation and more efficient handling by enable more accurate representation and more efficient handling by
the system. The implicit constants are described below; explicit the system. The implicit constants are described below; explicit
...@@ -271,8 +271,9 @@ SELECT 'foobar'; ...@@ -271,8 +271,9 @@ SELECT 'foobar';
<programlisting> <programlisting>
SELECT 'foo' 'bar'; SELECT 'foo' 'bar';
</programlisting> </programlisting>
is not valid syntax, and <productname>PostgreSQL</productname> is is not valid syntax. (This slightly bizarre behavior is specified
consistent with <acronym>SQL9x</acronym> in this regard. by <acronym>SQL9x</acronym>; <productname>PostgreSQL</productname> is
following the standard.)
</para> </para>
</sect3> </sect3>
...@@ -290,52 +291,52 @@ SELECT 'foo' 'bar'; ...@@ -290,52 +291,52 @@ SELECT 'foo' 'bar';
opening quote (no intervening whitespace), e.g., opening quote (no intervening whitespace), e.g.,
<literal>B'1001'</literal>. The only characters allowed within <literal>B'1001'</literal>. The only characters allowed within
bit-string constants are <literal>0</literal> and bit-string constants are <literal>0</literal> and
<literal>1</literal>. Bit-string constants can be continued <literal>1</literal>.
across lines in the same way as regular string constants.
</para> </para>
</sect3>
<sect3> <para>
<title>Integer Constants</title> Alternatively, bit-string constants can be specified in hexadecimal
notation, using a leading <literal>X</literal> (upper or lower case),
e.g., <literal>X'1FF'</literal>. This notation is equivalent to
a bit-string constant with four binary digits for each hex digit.
</para>
<para> <para>
Integer constants in SQL are sequences of decimal digits (0 Both forms of bit-string constant can be continued
though 9) with no decimal point and no exponent. The range of legal values across lines in the same way as regular string constants.
depends on which integer data type is used, but the plain
<type>integer</type> type accepts values ranging from -2147483648
to +2147483647. (The optional plus or minus sign is actually a
separate unary operator and not part of the integer constant.)
</para> </para>
</sect3> </sect3>
<sect3> <sect3>
<title>Floating-Point Constants</title> <title>Numeric Constants</title>
<indexterm> <indexterm>
<primary>floating point</primary> <primary>numeric</primary>
<secondary>constants</secondary> <secondary>constants</secondary>
</indexterm> </indexterm>
<para> <para>
Floating-point constants are accepted in these general forms: Numeric constants are accepted in these general forms:
<synopsis> <synopsis>
<replaceable>digits</replaceable>
<replaceable>digits</replaceable>.<optional><replaceable>digits</replaceable></optional><optional>e<optional>+-</optional><replaceable>digits</replaceable></optional> <replaceable>digits</replaceable>.<optional><replaceable>digits</replaceable></optional><optional>e<optional>+-</optional><replaceable>digits</replaceable></optional>
<optional><replaceable>digits</replaceable></optional>.<replaceable>digits</replaceable><optional>e<optional>+-</optional><replaceable>digits</replaceable></optional> <optional><replaceable>digits</replaceable></optional>.<replaceable>digits</replaceable><optional>e<optional>+-</optional><replaceable>digits</replaceable></optional>
<replaceable>digits</replaceable>e<optional>+-</optional><replaceable>digits</replaceable> <replaceable>digits</replaceable>e<optional>+-</optional><replaceable>digits</replaceable>
</synopsis> </synopsis>
where <replaceable>digits</replaceable> is one or more decimal where <replaceable>digits</replaceable> is one or more decimal
digits. At least one digit must be before or after the decimal digits (0 through 9). At least one digit must be before or after the
point. At least one digit must follow the exponent delimiter decimal point, if one is used. At least one digit must follow the
(<literal>e</literal>) if that field is present. exponent marker (<literal>e</literal>), if one is present.
Thus, a floating-point constant is distinguished from an integer There may not be any spaces or other characters embedded in the
constant by the presence of either the decimal point or the constant. Notice that any leading plus or minus sign is not actually
exponent clause (or both). There must not be a space or other considered part of the constant; it is an operator applied to the
characters embedded in the constant. constant.
</para> </para>
<para> <para>
These are some examples of valid floating-point constants: These are some examples of valid numeric constants:
<literallayout> <literallayout>
42
3.5 3.5
4. 4.
.001 .001
...@@ -345,14 +346,29 @@ SELECT 'foo' 'bar'; ...@@ -345,14 +346,29 @@ SELECT 'foo' 'bar';
</para> </para>
<para> <para>
Floating-point constants are of type <type>DOUBLE A numeric constant that contains neither a decimal point nor an
PRECISION</type>. <type>REAL</type> can be specified explicitly exponent is initially presumed to be type <type>integer</> if its
by using <acronym>SQL</acronym> string notation or value fits in type <type>integer</> (32 bits); otherwise it is
<productname>PostgreSQL</productname> type notation: presumed to be type <type>bigint</> if its
value fits in type <type>bigint</> (64 bits); otherwise it is
taken to be type <type>numeric</>. Constants that contain decimal
points and/or exponents are always initially presumed to be type
<type>numeric</>.
</para>
<para>
The initially assigned data type of a numeric constant is just a
starting point for the type resolution algorithms. In most
cases the constant will be automatically coerced to the most
appropriate type depending on context. When necessary, you
can force a numeric value to be interpreted as a specific
data type by casting it. For example, you can force a numeric
value to be treated as type <type>real</> (<type>float4</>)
by writing
<programlisting> <programlisting>
REAL '1.23' -- string style REAL '1.23' -- string style
'1.23'::REAL -- PostgreSQL (historical) style 1.23::REAL -- PostgreSQL (historical) style
</programlisting> </programlisting>
</para> </para>
</sect3> </sect3>
...@@ -921,7 +937,7 @@ SELECT 3 OPERATOR(pg_catalog.+) 4; ...@@ -921,7 +937,7 @@ SELECT 3 OPERATOR(pg_catalog.+) 4;
table (possibly qualified), or an alias for a table defined by means of a table (possibly qualified), or an alias for a table defined by means of a
FROM clause, or FROM clause, or
the key words <literal>NEW</literal> or <literal>OLD</literal>. the key words <literal>NEW</literal> or <literal>OLD</literal>.
(NEW and OLD can only appear in the action portion of a rule, (NEW and OLD can only appear in rules,
while other correlation names can be used in any SQL statement.) while other correlation names can be used in any SQL statement.)
The correlation name and separating dot may be omitted if the column name The correlation name and separating dot may be omitted if the column name
is unique is unique
...@@ -939,8 +955,9 @@ SELECT 3 OPERATOR(pg_catalog.+) 4; ...@@ -939,8 +955,9 @@ SELECT 3 OPERATOR(pg_catalog.+) 4;
<para> <para>
A positional parameter reference is used to indicate a parameter A positional parameter reference is used to indicate a parameter
in an SQL function. Typically this is used in SQL function that is supplied externally to an SQL statement. Parameters are
definition statements. The form of a parameter is: used in SQL function definitions and in prepared queries.
The form of a parameter reference is:
<synopsis> <synopsis>
$<replaceable>number</replaceable> $<replaceable>number</replaceable>
</synopsis> </synopsis>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/tutorial.sgml,v 1.15 2001/09/02 23:27:49 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/tutorial.sgml,v 1.16 2002/10/20 05:05:46 tgl Exp $
--> -->
<book id="tutorial"> <book id="tutorial">
...@@ -25,13 +25,9 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/tutorial.sgml,v 1.15 2001/09/02 23:27 ...@@ -25,13 +25,9 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/tutorial.sgml,v 1.15 2001/09/02 23:27
</para> </para>
<para> <para>
After you have worked through this tutorial you might want to move on After you have worked through this tutorial you might want to move on to
to reading the <![%single-book;[<citetitle>User's reading &cite-user; to gain a more formal knowledge of the SQL language,
Guide</citetitle>]]><![%set-of-books;[<xref linkend="user">]]> to or &cite-programmer; for information about developing applications for
gain a more formal knowledge of the SQL language, or the
<![%single-book;[<citetitle>Programmer's
Guide</citetitle>]]><![%set-of-books;[<xref linkend="programmer">]]>
for information about developing applications for
<productname>PostgreSQL</productname>. <productname>PostgreSQL</productname>.
</para> </para>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment