-
+
Data Definition
price numeric NOT NULL CHECK (price > 0)
);
- The order doesn't matter. It does not necessarily affect in which
+ The order doesn't matter. It does not necessarily determine in which
order the constraints are checked.
least) two rows in the table where the values of each of the
corresponding columns that are part of the constraint are equal.
However, null values are not considered equal in this
- consideration. That means, in the presence of a multicolumn
+ consideration. That means even in the presence of a
unique constraint it is possible to store an unlimited number of
rows that contain a null value in at least one of the constrained
columns. This behavior conforms to the SQL standard, but we have
A primary key indicates that a column or group of columns can be
used as a unique identifier for rows in the table. (This is a
direct consequence of the definition of a primary key. Note that
- a unique constraint does not, in fact, provide a unique identifier
+ a unique constraint does not, by itself, provide a unique identifier
because it does not exclude null values.) This is useful both for
documentation purposes and for client applications. For example,
a GUI application that allows modifying row values probably needs
In this case, a row of capitals inherits all
attributes (name, population, and altitude) from its
parent, cities. The type of the attribute name is
-
text, a native
PostgreSQL type for variable length
- ASCII strings. The type of the attribute population is
+
text, a native
PostgreSQL type
+ for variable length character strings. The type of the attribute
+ population is
float, a native
PostgreSQL type for double precision
floating-point numbers. State capitals have an extra
attribute, state, that shows their state. In
PostgreSQL,
In previous versions of
PostgreSQL, the
default was not to get access to child tables. This was found to
- be error prone and is also in violation of the SQL standard. Under the old
+ be error prone and is also in violation of the SQL99 standard. Under the old
syntax, to get the sub-tables you append * to the table name.
For example
To change the owner of a table, index, sequence, or view, use the
- ALTER TABLE command.
+
+ command.
USAGE>, and ALL PRIVILEGES>. For complete
information on the different types of privileges supported by
- GRANT reference page. The following sections
+
+ reference page. The following sections
and chapters will also show you how those privileges are used.
$user,public
The first element specifies that a schema with the same name as
- the current user is to be searched. Since no such schema exists
- yet, this entry is ignored. The second element refers to the
+ the current user is to be searched. If no such schema exists,
+ the entry is ignored. The second element refers to the
public schema that we have seen already.
the possible dependencies varies with the type of the object. You
can also write RESTRICT instead of
CASCADE to get the default behavior which is to
- restrict drops of objects that other objects depend on.
+ prevent drops of objects that other objects depend on.
-
+
Queries
- When using LIMIT>, it is a good idea to use an
+ When using LIMIT>, it is important to use an
ORDER BY> clause that constrains the result rows into a
unique order. Otherwise you will get an unpredictable subset of
- the query's rows. --- You may be asking for the tenth through
+ the query's rows. You may be asking for the tenth through
twentieth rows, but tenth through twentieth in what ordering? The
ordering is unknown, unless you specified ORDER BY>.
'{{1,2,3},{4,5,6},{7,8,9}}'
This constant is a two-dimensional, 3-by-3 array consisting of three
- subarrays of integers.
-
-
- Individual array elements can be placed between double-quote
- marks (") to avoid ambiguity
- problems with respect to whitespace. Without quote marks, the
- array-value parser will skip leading whitespace.
+ subarrays of integers. For more information see .
one of the two standard cast syntaxes is used to do a run-time
conversion, it will internally invoke a registered function to
perform the conversion. By convention, these conversion functions
- have the same name as their output type, but this is not something
- that a portable application should rely on.)
+ have the same name as their output type, and thus the function-like
+ syntax> is nothing more than a direct invocation of the underlying
+ conversion function. Obviously, this is not something that a portable
+ application should rely on.)
SELECT ... WHERE CASE WHEN x <> 0 THEN y/x > 1.5 ELSE false END;
- A CASE> construct used in this fashion will defeat optimization attempts,
- so it should only be done when necessary.
+ A CASE> construct used in this fashion will defeat optimization
+ attempts, so it should only be done when necessary. (In this particular
+ example, it would doubtless be best to sidestep the problem by writing
+ y > 1.5*x> instead.)
-UNION and CASE constructs
+UNION, CASE, and ARRAY constructs
-Since all query results from a unionized SELECT statement must appear in a single
-set of columns, the types of the results
-of each SELECT> clause must be matched up and converted to a uniform set.
-Similarly, the branch expressions of a CASE> construct must be converted to
-a common type so that the CASE> expression as a whole has a known output type.
+Since all query results from a unionized SELECT statement
+must appear in a single set of columns, the types of the results of each
+SELECT> clause must be matched up and converted to a uniform set.
+Similarly, the branch expressions of a CASE> construct must be
+converted to a common type so that the CASE> expression as a whole
+has a known output type. The same holds for ARRAY> constructs.
-
UNION> and CASE> Constructs
+
UNION, CASE, and
+ARRAY Constructs
SQL UNION> constructs must match up possibly dissimilar types to
to each output column of a union query. The INTERSECT> and
EXCEPT> constructs resolve dissimilar types in the same way as
UNION>.
-A CASE> construct also uses the identical algorithm to match up its
-component expressions and select a result data type.
+A CASE> construct uses the identical algorithm to match up its
+component expressions and select a result data type, as does ARRAY>.
-
UNION> and CASE> Type Resolution
+
UNION, CASE, and
+ARRAY Type Resolution