Skip to content

Commit 2c9c13e

Browse files
committed
update dump_stat.sgml draft: INSERT query, text style changes, fixes
1 parent 088b306 commit 2c9c13e

File tree

1 file changed

+53
-23
lines changed

1 file changed

+53
-23
lines changed

doc/src/sgml/dump_stat.sgml

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@
99

1010
<para>
1111
The <filename>dump_stat</> module provides functions that allow you to
12-
backup and recover the contents of the pg_statistic table. The
13-
<function>dump_statistic</> function generates <literal>INSERT</> statements which
14-
can later be applied to a compatible PostgreSQL server. The extension
12+
backup and recover the contents of the
13+
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
14+
table. The <function>dump_statistic</> function generates <literal>INSERT</>
15+
statements which can later be applied to a compatible database. The extension
1516
should be installed on the recipient server in order to successfuly restore
16-
statistical data since these statements rely on the provided functions.
17+
statistical data since these statements heavily rely on the provided functions.
18+
</para>
19+
20+
<para>
21+
Note that the definition of the
22+
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
23+
table might change occasionally, which means that generated dump might be incompatible
24+
with future releases of PostgreSQL.
1725
</para>
1826

1927
<sect2>
@@ -33,10 +41,29 @@
3341
<function>dump_statistic</function> dumps the contents of the
3442
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
3543
system catalog. It produces an <literal>INSERT</> statement
36-
per each tuple of the <literal>pg_statistic</>, excluding
37-
the ones that contain statistical data for tables in
38-
<literal>information_schema</> and <literal>pg_catalog</>
39-
schemas.
44+
per each tuple of the
45+
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>,
46+
excluding the ones that contain statistical data for tables in the
47+
<literal>information_schema</> and <literal>pg_catalog</> schemas.
48+
</para>
49+
50+
<para>
51+
The <literal>INSERT</> statement takes form of
52+
<screen>
53+
WITH upsert as (
54+
UPDATE pg_catalog.pg_statistic SET %s
55+
WHERE to_schema_qualified_relation(starelid) = relname
56+
AND to_attname(relname, staattnum) = attname
57+
AND to_atttype(relname, staattnum) = atttype
58+
AND stainherit = r.stainherit
59+
RETURNING *)
60+
ins as (
61+
SELECT %s
62+
WHERE NOT EXISTS (SELECT * FROM upsert)
63+
AND to_attnum(relname, attname) IS NOT NULL
64+
AND to_atttype(relname, attname) = atttype)
65+
INSERT INTO pg_catalog.pg_statistic SELECT * FROM ins;
66+
</screen>
4067
</para>
4168
</listitem>
4269
</varlistentry>
@@ -54,10 +81,10 @@
5481
<function>dump_statistic</function> dumps the contents of the
5582
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
5683
system catalog. It produces an <literal>INSERT</> statement
57-
per each tuple of the <literal>pg_statistic</>, excluding
58-
the ones that contain statistical data for tables in
59-
<literal>information_schema</> and <literal>pg_catalog</>
60-
schemas.
84+
per each tuple of the
85+
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>,
86+
excluding the ones that do not relate to the tables in
87+
<literal>schema_name</> schema.
6188
</para>
6289
</listitem>
6390
</varlistentry>
@@ -75,10 +102,10 @@
75102
<function>dump_statistic</function> dumps the contents of the
76103
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
77104
system catalog. It produces an <literal>INSERT</> statement
78-
per each tuple of the <literal>pg_statistic</>, excluding
79-
the ones that contain statistical data for tables in
80-
<literal>information_schema</> and <literal>pg_catalog</>
81-
schemas.
105+
per each tuple of the
106+
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>,
107+
excluding the ones that do not relate to the specified
108+
<literal>"schema_name.table_name"</> table.
82109
</para>
83110
</listitem>
84111
</varlistentry>
@@ -138,7 +165,7 @@
138165

139166
<listitem>
140167
<para>
141-
Returns the element type of the given array as oid.
168+
Returns the element type of the given array as <literal>oid</>.
142169
</para>
143170
</listitem>
144171
</varlistentry>
@@ -153,7 +180,8 @@
153180

154181
<listitem>
155182
<para>
156-
Given a relation name and a column number, returns the column name as text.
183+
Given a relation name and a column number, returns the column name
184+
as <literal>text</>.
157185
</para>
158186
</listitem>
159187
</varlistentry>
@@ -168,7 +196,8 @@
168196

169197
<listitem>
170198
<para>
171-
Given a relation name and a column name, returns the column number as int2.
199+
Given a relation name and a column name, returns the column number
200+
as <literal>int2</>.
172201
</para>
173202
</listitem>
174203
</varlistentry>
@@ -183,7 +212,8 @@
183212

184213
<listitem>
185214
<para>
186-
Given a relation name and a column name, returns the column type as text.
215+
Given a relation name and a column name, returns the column type
216+
as <literal>text</>.
187217
</para>
188218
</listitem>
189219
</varlistentry>
@@ -201,7 +231,7 @@
201231
<function>to_namespace</function> duplicates the behavior of
202232
the cast to <literal>regnamespace</> type, which is not
203233
present in the 9.4 release (and prior releases). This
204-
function returns the oid of the given namespace.
234+
function returns the <literal>oid</> of the given schema.
205235
</para>
206236
</listitem>
207237
</varlistentry>
@@ -216,8 +246,8 @@
216246

217247
<listitem>
218248
<para>
219-
<function>get_namespace</function> returns the namespace
220-
of the given relation as oid.
249+
<function>get_namespace</function> returns the schema
250+
of the given relation as <literal>oid</>.
221251
</para>
222252
</listitem>
223253
</varlistentry>

0 commit comments

Comments
 (0)