1<!--
2doc/src/sgml/ref/discard.sgml
3PostgreSQL documentation
4-->
5
6<refentry id="sql-discard">
7 <indexterm zone="sql-discard">
8  <primary>DISCARD</primary>
9 </indexterm>
10
11 <refmeta>
12  <refentrytitle>DISCARD</refentrytitle>
13  <manvolnum>7</manvolnum>
14  <refmiscinfo>SQL - Language Statements</refmiscinfo>
15 </refmeta>
16
17 <refnamediv>
18  <refname>DISCARD</refname>
19  <refpurpose>discard session state</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23<synopsis>
24DISCARD { ALL | PLANS | SEQUENCES | TEMPORARY | TEMP }
25</synopsis>
26 </refsynopsisdiv>
27
28 <refsect1>
29  <title>Description</title>
30
31  <para>
32   <command>DISCARD</command> releases internal resources associated with a
33   database session.  This command is useful for partially or fully
34   resetting the session's state.  There are several subcommands to
35   release different types of resources; the <command>DISCARD ALL</command>
36   variant subsumes all the others, and also resets additional state.
37  </para>
38 </refsect1>
39
40 <refsect1>
41  <title>Parameters</title>
42
43  <variablelist>
44
45   <varlistentry>
46    <term><literal>PLANS</literal></term>
47    <listitem>
48     <para>
49      Releases all cached query plans, forcing re-planning to occur
50      the next time the associated prepared statement is used.
51     </para>
52    </listitem>
53   </varlistentry>
54
55   <varlistentry>
56    <term><literal>SEQUENCES</literal></term>
57    <listitem>
58     <para>
59      Discards all cached sequence-related state,
60      including <function>currval()</function>/<function>lastval()</function>
61      information and any preallocated sequence values that have not
62      yet been returned by <function>nextval()</function>.
63      (See <xref linkend="sql-createsequence"/> for a description of
64      preallocated sequence values.)
65     </para>
66    </listitem>
67   </varlistentry>
68
69   <varlistentry>
70    <term><literal>TEMPORARY</literal> or <literal>TEMP</literal></term>
71    <listitem>
72     <para>
73      Drops all temporary tables created in the current session.
74     </para>
75    </listitem>
76   </varlistentry>
77
78   <varlistentry>
79    <term><literal>ALL</literal></term>
80    <listitem>
81     <para>
82      Releases all temporary resources associated with the current
83      session and resets the session to its initial state.
84      Currently, this has the same effect as executing the following sequence
85      of statements:
86<programlisting>
87CLOSE ALL;
88SET SESSION AUTHORIZATION DEFAULT;
89RESET ALL;
90DEALLOCATE ALL;
91UNLISTEN *;
92SELECT pg_advisory_unlock_all();
93DISCARD PLANS;
94DISCARD TEMP;
95DISCARD SEQUENCES;
96</programlisting></para>
97    </listitem>
98   </varlistentry>
99
100  </variablelist>
101 </refsect1>
102
103 <refsect1>
104  <title>Notes</title>
105
106   <para>
107    <command>DISCARD ALL</command> cannot be executed inside a transaction block.
108   </para>
109 </refsect1>
110
111 <refsect1>
112  <title>Compatibility</title>
113
114  <para>
115   <command>DISCARD</command> is a <productname>PostgreSQL</productname> extension.
116  </para>
117 </refsect1>
118</refentry>
119