WARNING

This text was automatically converted from troff me macros to HTML. Information may have been lost, added, or changed in the process. Lars Aronsson and Lysator do not guarantee the correctness of this HTML document.

"SECTION 4 *- POSTQUEL COMMANDS (COMMANDS)"

DESCRIPTION

The following is a description of the general syntax of POSTQUEL. Individual POSTQUEL statements and commands are treated separately in the document; this section describes the syntactic classes from which the constituent parts of POSTQUEL statements are drawn.

Comments

A comment is an arbitrary sequence of characters bounded on the left by ``/*'' and on the right by ``*/'', e.g:

/* This is a comment */

Names

Names in POSTQUEL are sequences of not more than 16 alphanumeric characters, starting with an alphabetic. Underscore (^_^) is considered an alphabetic.

Keywords

The following identifiers are reserved for use as keywords and may not be used otherwise:

s3
xx abort delete key remove 
xx addattr demand leftouter rename 
xx after descending light replace
xx all destroy load retrieve
xx always destroydb merge returns
xx and do move rewrite
xx append empty never rightouter 
xx arch_store end new rule
xx archive execute none sort
xx arg fetch nonulls stdin
xx ascending forward not stdout
xx attachas from NULL store
xx backward function on to
xx before heavy once transaction
xx begin in operator type
xx binary index or union
xx by indexable output_proc unique
xx cfunction inherits parallel using
xx close input_proc pfunction vacuum
xx cluster instance portal variable
xx copy instead postquel version
xx create intersect priority view
xx createdb into purge where
xx current intotemp quel with
xx define is relation

In addition, all POSTGRES classes have several predefined attributes used by the system. For a list of these, see the section Fields , below.

Constants

There are six types of constants for use in POSTQUEL. They are described below.

Character Constants

Single "character constants" may be used in POSTQUEL by surrounding them by single quotes, e.g., `n'.

String Constants

Strings in POSTQUEL are arbitrary sequences of ASCII characters bounded by double quotes (" "). Upper case alphabetics within strings are accepted literally. Non-printing characters may be embedded within strings by prepending them with a backslash, e.g., `\n'. Also, in order to embed quotes within strings, it is necessary to prefix them with `\' . The same convention applies to `\' itself. Because of the limitations on instance sizes, string constants are currently limited to a length of a little less than 8K bytes. Larger objects may be created using the POSTGRES Large Object interface.

Integer Constants

"Integer constants" in POSTQUEL are collection of ASCII digits with no decimal point. Legal values range from (mi2147483647 to +2147483647. This will vary depending on the operating system and host machine.

Floating Point Constants

"Floating point constants" consist of an integer part, a decimal point, and a fraction part or scientific notation of the following format:

{<dig>} .{<dig>} [e [+-] {<dig>}]

Where <dig> is a digit. You must include at least one <dig> after the period and after the [+-] if you use those options. An exponent with a missing mantissa has a mantissa of 1 inserted. There may be no extra characters embedded in the string. Floating constants are taken to be double-precision quantities with a range of approximately and a precision of 17 decimal digits. This will vary depending on the operating system and host machine.

Constants of POSTGRES User Defined Types

A constant of an arbitrary type can be entered using the notation:

"string"::type-name
In this case the value inside the string is passed to the input conversion routine for the type called type-name. The result is a constant of the indicated type.

Array constants

"Array constants" are arrays of any POSTGRES type, including other arrays, string constants, etc. The general format of an array constant is the following:

"{<val1><delim><val2><delim>}"

An example of an array constant is

"{{1,2,3},{4,5},{6,7,8,9}}"

This constant is an array consisting of three sub-arrays of integers.

Fields

A field is one of the following:

attribute name in a given class
all
oid
tmin
tmax
xmin
xmax
cmin
cmax
vtype
As in INGRES, all is a shorthand for all normal attributes in a class, and may be used profitably in the target list of a retrieve statement. Oid stands for the unique identifier of an instance which is added by POSTGRES to all instances automatically. Oids are not reused and are 32 bit quantities.

"Tmin, tmax, xmin, cmin, xmax" and cmax stand respectively for the time that the instance was inserted, the time the instance was deleted, the identity of the inserting transaction, the command identifier within the transaction, the identity of the deleting transaction and its associated deleting command. For further information on these fields consult [STON87]. Times are represented internally as instances of the abstime data type. Transaction identifiers are 32 bit quantities which are assigned sequentially starting at 512. Command identifiers are 16 bit objects; hence, it is an error to have more than 65535 POSTQUEL commands within one transaction.

Attributes

An attribute is a construct of the form:

Instance-variable{.composite_field}.field `['number`]'
Instance-variable identifies a particular class and can be thought of as standing for the instances of that class. An instance variable is either a class name, a surrogate for a class defined by means of a from clause, or the keyword new or current. New and current can only appear in the action portion of a rule, while other instance variables can be used in any POSTQUEL command. Composite_field is a field of of one of the POSTGRES composite types indicated in the information(commands) section, while successive composite fields address attributes in the class(s) to which the composite field evaluates. Lastly, field is a normal (base type) field in the class(s) last addressed. If field is of type array, then the optional number designator indicates a specific element in the array. If no number is indicated, then all array elements are returned.

Operators

Any built-in system, or user defined operator may be used in POSTQUEL. For the list of built-in and system operators consult built-in types (commands) and b. system types (commands). For a list of user defined operators consult your system administrator or run a query on the pg_operator class. Parentheses may be used for arbitrary grouping of operators.

Expressions (a_expr)

An expression is one of the following:

( a_expr )
constant
attribute
a_expr  binary_operator  a_expr
left_unary_operator  a_expr
parameter
functional expressions 
aggregate expressions
set expressions
class expression (not in Version 4.0)
We have already discussed constants and attributes. The two kinds of operator expressions indicate respectively binary and left_unary expressions. The following sections discuss the remaining options.

Parameters

A parameter is used to indicate a parameter in a POSTQUEL function. Typically this is used in POSTQUEL function definition statement. The form of a parameter is:

'$' number

For example, consider the definition of a function, DEPT, as

define function DEPT 
 (language="postquel", returntype = dept)
    arg is (char16) as 
    retrieve (dept.all) where dept.name = $1

Functional Expressions

A functional expression is the name of a legal POSTQUEL function, followed by its argument list enclosed in parentheses, e.g.:

fn-name (a_expr{ , a_expr})
For example, the following computes the square root of an employee salary.
sqrt(emp.salary)

Aggregate Expression

An aggregate expression represents a simple aggregate (i.e one which computes a single value) or an aggregate function (i.e. one which computes a set of values). The syntax is the following:

aggregate_name `{' [unique [using] opr] a_expr
  [from from_list]
  [where qualification]`}'
Here, aggregate_name must be a previously defined aggregate. The from_list indicates the class to be aggregated over while qualification gives restrictions which must be satisfied by the instances to be aggregated. Next, the a_expr gives the expression to be aggregated while the unique tag indicates whether all values should be aggregated or just the unique values of a_expr. Two expressions, a_expr1 and a_expr2 are the same if a_expr1 opr a_expr2 evaluates to true.

In the case that all instance variables used in the aggregate expression are defined in the from list, a simple aggregate has been defined. For example, to sum employee salaries whose age is greater than 30, one would write:

retrieve (total = sum {e.salary from e in emp
                                where e.age > 30} )
or
retrieve (total = sum {EMP.salary where emp.age > 30})
In either case, POSTGRES is instructed to find the instances in the from_list which satisfy the qualification and then compute the aggregate of the a_expr indicated.

On the other hand, if there are variables used in the aggregate expression that are not defined in the from list, e.g:

avg {emp.salary where emp.age = e.age}
then this aggregate has a value for each possible value taken on by e.age. For example, the following complete query finds the average salary of each possible employee age over 18:
retrieve (e.age, avg {emp.salary where emp.age = e.age})
 from e in emp 
 where e.age > 18
Such aggregate functions are not supported in Version 4.0. Furthermore, in this version, only the a_expr and the where-qualification clause are supported. Therefore, for the above simple sum aggregate, the supported query would be the latter. One other note: the qualification will support inheritance, but the expression to be aggregated will not.

Set Expressions

Set expressions are not supported in Version 4.0.

A set expression defines a collection of instances from some class and uses the following syntax:

 {target_list from from_list where qualification}
For example, the set of all employee names over 40 is:
{emp.name where emp.age > 40}
In addition, it is legal to construct set expressions which have an instance variable which is defined outside the scope of the expression. For example, the following expression is the set of employees in each department:
{emp.name where emp.dept = dept.dname}
Set expressions can be used in class expressions which are defined below.

Class Expression

Class expressions are not supported in Version 4.0.

A class expression is an expression of the form:

class_constructor binary_class_operator class_constructor
unary_class_operator class_constructor
where binary_class_operator is one of the following:
union  union of two classes
intersect intersection of two classes
-  difference of two classes
>>  left class contains right class
<<  right class contains left class
==  right class equals left class 
and unary_class_operator can be:
empty  right class is empty
A class_constructor is either an instance variable, a class name, the value of a composite field or a set expression.

An example of a query with a class expression is one to find all the departments with no employees:

retrieve (dept.dname)
    where empty {emp.name where emp.dept = dept.dname}

Target_list

A "target list" is a parenthesized, comma-separated list of one or more elements, each of which must be of the form:

[result_attname  =] a_expr
Here, result_attname is the name of the attribute to be created (or an already existing attribute name in the case of update statements.) If result_attname is not present, then a_expr must contain only one attribute name which is assumed to be the name of the result field. In Version 4.0 default naming is only used if the a_expr is an attribute.

Qualification

A qualification consists of any number of clauses connected by the logical operators:

not
and
or
A clause is an a_expr that evaluates to a Boolean over a set of instances.

From List

The from list is a comma-separated list of from expressions.

Each from expression is of the form:

instance_variable-1 {, instance_variable-2}
 in class_reference
where class_reference is of the form
class_name [time_expression] [*]
The from expression defines one or more instance variables to range over the class indicated in class_reference. Adding a time_expression will indicate that a historical class is desired. One can also request the instance variable to range over all classes that are beneath the indicated class in the inheritance hierarchy by postpending the designator `*'.

Time Expressions

A time expression is in one of two forms:

 [date]
 [date-1, date-2]
The first case requires instances that are valid at the indicated time. The second case requires instances that are valid at some time within the date range specified. If no time expression is indicated, the default is now.

In each case, the date is a character string of the form


[MON-FRI] "MMM DD [HH:MM:SS] YYYY" [Timezone]
fn
where MMM is the month (Jan - Dec), DD is a legal day number in the specified month, HH:MM:SS is an optional time in that day (24-hour clock), and YYYY is the year. If the time of day HH:MM:SS is not specified, it defaults to midnight at the start of the specified day. In addition, all times are interpreted as GMT.

For example,


["Jan 1 1990"]
["Mar 3 00:00:00 1980", "Mar 3 23:59:59 1981"]
fn
are valid time specifications.

SEE ALSO

append(commands), delete(commands), execute(commands), replace(commands), retrieve(commands), monitor(unix).

BUGS

The following constructs are not available in Version 4.0:

class expressions
set expressions