1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-22 17:42:17 +03:00
Files
postgres/doc/src/sgml/ref/savepoint.sgml
Peter Eisentraut 9081bddbd7 Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>.  But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.

We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.

We can't put the <xref> inside the <command>; the DTD doesn't allow
this.  DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.

So to solve this for now, convert the <xref>s to <link> plus
<command>.  This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses).  In the future, these could then be converted to
DocBook 5 style.

I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better.  Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>.  In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.

Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:40:02 +02:00

138 lines
3.6 KiB
Plaintext

<!--
doc/src/sgml/ref/savepoint.sgml
PostgreSQL documentation
-->
<refentry id="sql-savepoint">
<indexterm zone="sql-savepoint">
<primary>SAVEPOINT</primary>
</indexterm>
<indexterm zone="sql-savepoint">
<primary>savepoints</primary>
<secondary>defining</secondary>
</indexterm>
<refmeta>
<refentrytitle>SAVEPOINT</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>SAVEPOINT</refname>
<refpurpose>define a new savepoint within the current transaction</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
SAVEPOINT <replaceable>savepoint_name</replaceable>
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>SAVEPOINT</command> establishes a new savepoint within
the current transaction.
</para>
<para>
A savepoint is a special mark inside a transaction that allows all commands
that are executed after it was established to be rolled back, restoring
the transaction state to what it was at the time of the savepoint.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><replaceable>savepoint_name</replaceable></term>
<listitem>
<para>
The name to give to the new savepoint.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
<para>
Use <link linkend="sql-rollback-to"><command>ROLLBACK TO</command></link> to
rollback to a savepoint. Use <link linkend="sql-release-savepoint"><command>RELEASE SAVEPOINT</command></link>
to destroy a savepoint, keeping
the effects of commands executed after it was established.
</para>
<para>
Savepoints can only be established when inside a transaction block.
There can be multiple savepoints defined within a transaction.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<para>
To establish a savepoint and later undo the effects of all commands executed
after it was established:
<programlisting>
BEGIN;
INSERT INTO table1 VALUES (1);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (2);
ROLLBACK TO SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (3);
COMMIT;
</programlisting>
The above transaction will insert the values 1 and 3, but not 2.
</para>
<para>
To establish and later destroy a savepoint:
<programlisting>
BEGIN;
INSERT INTO table1 VALUES (3);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (4);
RELEASE SAVEPOINT my_savepoint;
COMMIT;
</programlisting>
The above transaction will insert both 3 and 4.
</para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para>
SQL requires a savepoint to be destroyed automatically when another
savepoint with the same name is established. In
<productname>PostgreSQL</productname>, the old savepoint is kept, though only the more
recent one will be used when rolling back or releasing. (Releasing the
newer savepoint with <command>RELEASE SAVEPOINT</command> will cause the older one
to again become accessible to <command>ROLLBACK TO SAVEPOINT</command> and
<command>RELEASE SAVEPOINT</command>.) Otherwise, <command>SAVEPOINT</command> is
fully SQL conforming.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-begin"/></member>
<member><xref linkend="sql-commit"/></member>
<member><xref linkend="sql-release-savepoint"/></member>
<member><xref linkend="sql-rollback"/></member>
<member><xref linkend="sql-rollback-to"/></member>
</simplelist>
</refsect1>
</refentry>