Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
58ae3cf1
Commit
58ae3cf1
authored
21 years ago
by
Neil Conway
Browse files
Options
Downloads
Patches
Plain Diff
Minor improvements to the trigger documentation, and a few SGML fixes.
parent
5ad7d65d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/src/sgml/plpgsql.sgml
+8
-8
8 additions, 8 deletions
doc/src/sgml/plpgsql.sgml
doc/src/sgml/trigger.sgml
+66
-36
66 additions, 36 deletions
doc/src/sgml/trigger.sgml
with
74 additions
and
44 deletions
doc/src/sgml/plpgsql.sgml
+
8
−
8
View file @
58ae3cf1
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.3
2
200
3/11/30 05:45:22 momjian
Exp $
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.3
3
200
4/01/22 19:50:21 neilc
Exp $
-->
-->
<chapter id="plpgsql">
<chapter id="plpgsql">
...
@@ -729,7 +729,7 @@ RENAME <replaceable>oldname</replaceable> TO <replaceable>newname</replaceable>;
...
@@ -729,7 +729,7 @@ RENAME <replaceable>oldname</replaceable> TO <replaceable>newname</replaceable>;
<para>
<para>
Using the <literal>RENAME</literal> declaration you can change the
Using the <literal>RENAME</literal> declaration you can change the
name of a variable, record or row. This is primarily useful if
name of a variable, record or row. This is primarily useful if
<
literal>NEW</literal> or <literal>OLD</literal
> should be
<
varname>NEW</varname> or <varname>OLD</varname
> should be
referenced by another name inside a trigger procedure. See also
referenced by another name inside a trigger procedure. See also
<literal>ALIAS</literal>.
<literal>ALIAS</literal>.
</para>
</para>
...
@@ -2176,7 +2176,7 @@ RAISE EXCEPTION ''Inexistent ID --> %'', user_id;
...
@@ -2176,7 +2176,7 @@ RAISE EXCEPTION ''Inexistent ID --> %'', user_id;
<para>
<para>
Data type <type>RECORD</type>; variable holding the new
Data type <type>RECORD</type>; variable holding the new
database row for <command>INSERT</>/<command>UPDATE</> operations in row-level
database row for <command>INSERT</>/<command>UPDATE</> operations in row-level
triggers. This variable is
null
in statement-level triggers.
triggers. This variable is
<symbol>NULL</symbol>
in statement-level triggers.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -2187,7 +2187,7 @@ RAISE EXCEPTION ''Inexistent ID --> %'', user_id;
...
@@ -2187,7 +2187,7 @@ RAISE EXCEPTION ''Inexistent ID --> %'', user_id;
<para>
<para>
Data type <type>RECORD</type>; variable holding the old
Data type <type>RECORD</type>; variable holding the old
database row for <command>UPDATE</>/<command>DELETE</> operations in row-level
database row for <command>UPDATE</>/<command>DELETE</> operations in row-level
triggers. This variable is
null
in statement-level triggers.
triggers. This variable is
<symbol>NULL</symbol>
in statement-level triggers.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -2281,9 +2281,9 @@ RAISE EXCEPTION ''Inexistent ID --> %'', user_id;
...
@@ -2281,9 +2281,9 @@ RAISE EXCEPTION ''Inexistent ID --> %'', user_id;
</para>
</para>
<para>
<para>
A trigger function must return either
null or a record/row value
A trigger function must return either
<symbol>NULL</symbol> or a
having exactly the structure of the table the
trigger was fired
record/row value
having exactly the structure of the table the
for.
trigger was fired
for.
</para>
</para>
<para>
<para>
...
...
This diff is collapsed.
Click to expand it.
doc/src/sgml/trigger.sgml
+
66
−
36
View file @
58ae3cf1
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.3
3
200
3/1
1/2
9
19:5
1:38 pgsql
Exp $
$PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.3
4
200
4/0
1/2
2
19:5
0:21 neilc
Exp $
-->
-->
<chapter id="triggers">
<chapter id="triggers">
...
@@ -45,50 +45,69 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.33 2003/11/29 19:51:38 pgsql Ex
...
@@ -45,50 +45,69 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.33 2003/11/29 19:51:38 pgsql Ex
</para>
</para>
<para>
<para>
Trigger functions return a table row (a value of type
There are two types of triggers: per-row triggers and
<structname>HeapTuple</>) to the calling executor.
per-statement triggers. In a per-row trigger, the trigger function
A trigger fired before an operation has the following choices:
is invoked once for every row that is affected by the statement
that fired the trigger. In contrast, a per-statement trigger is
invoked only once when an appropriate statement is executed,
regardless of the number of rows affected by that statement. In
particular, a statement that affects zero rows will still result
in the execution of any applicable per-statement triggers. These
two types of triggers are sometimes called <quote>row-level
triggers</quote> and <quote>statement-level triggers</quote>,
respectively.
</para>
<para>
Trigger functions invoked by per-statement triggers should always
return <symbol>NULL</symbol>. Trigger functions invoked by per-row
triggers can return a table row (a value of
type <structname>HeapTuple</structname>) to the calling executor,
if they choose. A row-level trigger fired before an operation has
the following choices:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
It can return a <symbol>NULL</> pointer to skip the operation
It can return <symbol>NULL</> to skip the operation for the
for the current row (and so the row will not be
current row. This instructs the executor to not perform the
inserted/updated/deleted).
row-level operation that invoked the trigger (the insertion or
modification of a particular table row).
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
For <command>INSERT</command>
and <command>UPDATE</command>
For
row-level
<command>INSERT</command>
triggers only, the returned row
becomes the row that will
and <command>UPDATE</command>
triggers only, the returned row
be inserted or will replace the row
being updated. This
becomes the row that will
be inserted or will replace the row
allows the trigger function to modify the
row being inserted or
being updated. This
allows the trigger function to modify the
updated.
row being inserted or
updated.
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
A before trigger that does not intend to cause either of these
A row-level before trigger that does not intend to cause either of
behaviors must be careful to return as its result the same row that was
these behaviors must be careful to return as its result the same
passed in (that is, the NEW row for <command>INSERT</command> and
row that was passed in (that is, the <varname>NEW</varname> row
<command>UPDATE</command> triggers, the OLD row for
for <command>INSERT</command> and <command>UPDATE</command>
triggers, the <varname>OLD</varname> row for
<command>DELETE</command> triggers).
<command>DELETE</command> triggers).
</para>
</para>
<para>
<para>
The return
The return value is ignored for row-level triggers fired after an
value is ignored for triggers fired after an operation, and so
operation, and so they may as well return <symbol>NULL</>.
they may as well return <symbol>NULL</>.
</para>
</para>
<para>
<para>
If more than one trigger is defined for the same event on the same
If more than one trigger is defined for the same event on the same
relation, the triggers will be fired in alphabetical order by trigger
relation, the triggers will be fired in alphabetical order by
name. In the case of before triggers, the possibly-modified row
trigger name. In the case of before triggers, the
returned by each trigger becomes the input to the next trigger.
possibly-modified row returned by each trigger becomes the input
If any before trigger returns a <symbol>NULL</> pointer, the
to the next trigger. If any before trigger returns
operation is abandoned and subsequent triggers are not fired.
<symbol>NULL</>, the operation is abandoned and subsequent
triggers are not fired.
</para>
</para>
<para>
<para>
...
@@ -134,30 +153,41 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.33 2003/11/29 19:51:38 pgsql Ex
...
@@ -134,30 +153,41 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.33 2003/11/29 19:51:38 pgsql Ex
is fired for. Briefly:
is fired for. Briefly:
<itemizedlist>
<itemizedlist>
<listitem>
<para>
Statement-level triggers follow simple visibility rules: none of
the changes made by a statement are visible to statement-level
triggers that are invoked before the statement, whereas all
modifications are visible to statement-level after triggers.
</para>
</listitem>
<listitem>
<listitem>
<para>
<para>
The data change (insertion, update, or deletion) causing the
trigger
The data change (insertion, update, or deletion) causing the
to fire is naturally
trigger
to fire is naturally
<emphasis>not</emphasis> visible
<emphasis>not</emphasis> visible to SQL commands executed in a
to SQL commands executed in a row-level before trigger, because
before trigger, because
it hasn't happened yet.
it hasn't happened yet.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
However, SQL commands executed in a
before trigger
However, SQL commands executed in a
row-level before
<emphasis>will</emphasis> see the effects of data
changes
trigger
<emphasis>will</emphasis> see the effects of data
for rows previously processed in the same outer
command. This
changes
for rows previously processed in the same outer
requires caution, since the ordering of these
change events
command. This
requires caution, since the ordering of these
is not in general predictable; a SQL command that
affects
change events
is not in general predictable; a SQL command that
multiple rows may visit the rows in any order.
affects
multiple rows may visit the rows in any order.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
When an after trigger is fired, all data changes made by the outer
When a row-level after trigger is fired, all data changes made
command are already complete, and are visible to executed SQL commands.
by the outer command are already complete, and are visible to
the invoked trigger function.
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment