From 64fbd1fb12a4783379b3f101d571381405d5126f Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Wed, 29 Jul 1998 06:23:26 +0000 Subject: [PATCH] Add new files from Oliver Elphick. --- doc/src/sgml/ref/commands.sgml | 142 ++++++--- doc/src/sgml/ref/create_trigger.sgml | 247 +++++++++++++++ doc/src/sgml/ref/create_type.sgml | 438 +++++++++++++++++++++++++++ 3 files changed, 789 insertions(+), 38 deletions(-) create mode 100644 doc/src/sgml/ref/create_trigger.sgml create mode 100644 doc/src/sgml/ref/create_type.sgml diff --git a/doc/src/sgml/ref/commands.sgml b/doc/src/sgml/ref/commands.sgml index 3edc715778..5e761b146f 100644 --- a/doc/src/sgml/ref/commands.sgml +++ b/doc/src/sgml/ref/commands.sgml @@ -1,43 +1,109 @@ - -Commands + - - + + -&alterTable; -&alterUser; -&begin; -&close; -&cluster; -&commit; -© -&createAggregate; -&createDatabase; -&createFunction; -&createIndex; -&createLanguage; -&createOperator; -&createRule; -&createSequence; -&createTable; -&dropFunction; -&select; + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/src/sgml/ref/create_trigger.sgml b/doc/src/sgml/ref/create_trigger.sgml new file mode 100644 index 0000000000..a183a80186 --- /dev/null +++ b/doc/src/sgml/ref/create_trigger.sgml @@ -0,0 +1,247 @@ + + + + CREATE TRIGGER + + SQL - Language Statements + + + + CREATE TRIGGER + + + CREATE TRIGGER - creates a new trigger. + + + + 1998-04-15 + + + CREATE TRIGGER name { BEFORE | AFTER } + { event [OR ...] } + ON table FOR EACH { ROW | STATEMENT } + EXECUTE PROCEDURE funcname ( arguments ) + + + + + 1998-04-15 + + + Inputs + + + + + + + + + + + + + name + + + + The name of an existing trigger. + + + + + + table + + + + The name of a table. + + + + + + event + + + + One of INSERT, DELETE or UPDATE. + + + + + + funcname + + + + A user-supplied function. + + + + + + + + + + + + 1998-04-15 + + + Outputs + + + + + + + + + + + + + CREATE + + + + This message is returned if the trigger is successfully created. + + + + + + + + + + + + + 1998-04-15 + + + Description + + + CREATE TRIGGER will enter a new trigger into the current + data base. The trigger will be associated with the relation + relname and will execute + the specified function funcname. + + + Only the relation owner may create a trigger on this relation. + + + At release 6.3.2, STATEMENT triggers are not implemented. + + + The trigger can be specified to fire either before the + operation is attempted on a tuple (before constraints + are checked and the INSERT, UPDATE or DELETE is attempted) or + after the operation has been attempted (e.g. after constraints + are checked and the INSERT, UPDATE or DELETE has completed). If the + trigger fires before the event, the trigger may + skip the operation for the current tuple, or change the tuple + being inserted (for INSERT and UPDATE operations only). If + the trigger fires after the event, all changes, including the + last INSERTion, UPDATE or DELETion, are "visible" to the trigger. + + + Refer to the SPI and trigger programming guides for more + information. + + + + 1998-04-15 + + + Notes + + + CREATE TRIGGER statement is a PostgreSQL language extension. + + + Refer to the DROP TRIGGER statement for information on how to + remove triggers. + + + + + + + Usage + + + Check if the specified distributor code exists in the distributors + table before appending or updating a row in the table films: + + + CREATE TRIGGER if_dist_exists + BEFORE INSERT OR UPDATE ON films FOR EACH ROW + EXECUTE PROCEDURE check_primary_key ('did', 'distributors', 'did'); + + + Before cancelling a distributor or updating its code, remove every + reference to the table films: + + + CREATE TRIGGER if_film_exists + BEFORE DELETE OR UPDATE ON distributors FOR EACH ROW + EXECUTE PROCEDURE check_foreign_key (1, 'CASCADE', 'did', 'films', 'did'); + + + + + + Compatibility + + + + + + + 1998-04-15 + + + SQL92 + + + There is no CREATE TRIGGER statement in SQL92. + + + The second example above may also be done by using a FOREIGN KEY + constraint as in: + + + CREATE TABLE distributors ( + did DECIMAL(3), + name VARCHAR(40), + CONSTRAINT if_film_exists FOREIGN KEY(did) REFERENCES films + ON UPDATE CASCADE ON DELETE CASCADE + ); + + + However, foreign keys are not yet implemented at version 6.3.2 of + PostgreSQL. + + + + \ No newline at end of file diff --git a/doc/src/sgml/ref/create_type.sgml b/doc/src/sgml/ref/create_type.sgml new file mode 100644 index 0000000000..2f1cc46a8d --- /dev/null +++ b/doc/src/sgml/ref/create_type.sgml @@ -0,0 +1,438 @@ + + + + CREATE TYPE + + SQL - Language Statements + + + + CREATE TYPE + + + CREATE TYPE - defines a new base data type. + + + + 1998-04-15 + + + CREATE TYPE typename ( + INTERNALLENGTH = (internallength | VARIABLE) + [, EXTERNALLENGTH = (externallength | VARIABLE) ] + +Why are parentheses required around the length parameters? + + , INPUT = input_function + , OUTPUT = output_function + [, ELEMENT = element] + [, DELIMITER = delimiter] + [, DEFAULT = "default" ] + [, SEND = send_function ] + [, RECEIVE = receive_function ] + [, PASSEDBYVALUE]) + + + + + 1998-04-15 + + + Inputs + + + + + + + + + + + + + + typename + + + + + The name of a type to be created. + + + + + + + internallength + + + + + A literal value, which specifies the internal length of + the new type. + + + + + + + externallength + + + + + A literal value, which specifies the external length of + the new type. + + + + + + + input_function + + + + + The name of a function, created by CREATE FUNCTION, which + converts data from its external form to the type's + internal form. + + + + + + + output_function + + + + + The name of a function, created by CREATE FUNCTION, which + converts data from its internal form to a form suitable + for display. + + + + + + + element + + + + + The type being created is an array; this specifies + the type of the array elements. + + + + + + + delimiter + + + + + The delimiter character for the array. + + + + + + + default + + + + The default text to be displayed to indicate "data + not present" + + + + + + + send_function + + + + + The name of a function, created by CREATE FUNCTION, which + converts data of this type into a form suitable for + transmission to another machine. +Is this right? + + + + + + + receive_function + + + + + The name of a function, created by CREATE FUNCTION, which + converts data of this type from a form suitable for + transmission from another machine to internal form. +Is this right? + + + + + + + + + + + + 1998-04-15 + + + Outputs + + + + + + + + + + + + + CREATE + + + + Message returned if the type is successfully created. + + + + + + + + + + + + + + 1998-04-15 + + + Description + + + CREATE TYPE allows the user to register a new user data + type with Postgres for use in the current data base. The + user who defines a type becomes its owner. + Typename is + the name of the new type and must be unique within the + types defined for this database. + + + CREATE TYPE requires the registration of two functions + (using create function) before defining the type. The + representation of a new base type is determined by + input_function, which + converts the type's external representation to an internal + representation usable by the + operators and functions defined for the type. Naturally, + output_function + performs the reverse transformation. Both + the input and output functions must be declared to take + one or two arguments of type "opaque". + + + New base data types can be fixed length, in which case + internallength is a + positive integer, or variable length, + in which case Postgres assumes that the new type has the + same format + as the Postgres-supplied data type, "text". + To indicate that a type is variable-length, set + internallength + to VARIABLE. + The external representation is similarly specified using the + externallength + keyword. + + + To indicate that a type is an array and to indicate that a + type has array elements, indicate the type of the array + element using the element keyword. For example, to define + an array of 4 byte integers ("int4"), specify + ELEMENT = int4 + + + To indicate the delimiter to be used on arrays of this + type, delimiter + can be + set to a specific character. The default delimiter is the comma + (","). + + + A default value is optionally available in case a user + wants some specific bit pattern to mean "data not present." + Specify the default with the DEFAULT keyword. +How does the user specify that bit pattern and associate +it with the fact that the data is not present> + + + The optional functions + send_function and + receive_function + are used when the application program requesting Postgres + services resides on a different machine. In this case, + the machine on which Postgres runs may use a format for the data + type different from that used on the remote machine. + In this case it is appropriate to convert data items to a + standard form when sending from the server to the client + and converting from the standard format to the machine + specific format when the server receives the data from the + client. If these functions are not specified, then it is + assumed that the internal format of the type is acceptable + on all relevant machine architectures. For example, single + characters do not have to be converted if passed from + a Sun-4 to a DECstation, but many other types do. + + + The optional flag, PASSEDBYVALUE, indicates that operators + and functions which use this data type should be passed an + argument by value rather than by reference. Note that you + may not pass by value types whose internal representation is + more than four bytes. + + + For new base types, a user can define operators, functions + and aggregates using the appropriate facilities described + in this section. + + + Array Types + + Two generalized built-in functions, array_in and + array_out, exist for quick creation of variable-length + array types. These functions operate on arrays of any + existing Postgres type. + + + + Large Object Types + + A "regular" Postgres type can only be 8192 bytes in + length. If you need a larger type you must create a Large + Object type. The interface for these types is discussed + at length in +This section reference needs replacing + Section 7, the large object interface. The + length of all large object types is always VARIABLE. + + + + Examples + + This command creates the box data type and then uses the + type in a class definition: + + + CREATE TYPE box (INTERNALLENGTH = 8, + INPUT = my_procedure_1, OUTPUT = my_procedure_2) + + CREATE TABLE myboxes (id INT4, description box) + + + This command creates a variable length array type with + integer elements. + + + CREATE TYPE int4array + (INPUT = array_in, OUTPUT = array_out, + INTERNALLENGTH = VARIABLE, ELEMENT = int4) + + CREATE TABLE myarrays (id int4, numbers int4array) + + + This command creates a large object type and uses it in + a class definition. + + + CREATE TYPE bigobj + (INPUT = lo_filein, OUTPUT = lo_fileout, + INTERNALLENGTH = VARIABLE) + + CREATE TABLE big_objs (id int4, obj bigobj) + + + Restrictions + + Type names cannot begin with the underscore character + ("_") and can only be 15 characters long. This is because + Postgres silently creates an array type for each base type + with a name consisting of the base type's name prepended + with an underscore. + + + + + 1998-04-15 + + + Notes + + + Refer to DROP TYPE statement to drop types. + + + See also CREATE FUNCTION, CREATE OPERATOR and large_objects. + + + + + + + Compatibility + + + CREATE TYPE statement is a PostgreSQL language extension. + + + + + 1998-04-15 + + + SQL3 + + + CREATE TYPE is a SQL3 statement. + + + + + + + \ No newline at end of file -- GitLab