OSDN Git Service

1.3.0
[pgdbmsstats/pg_dbms_stats.git] / export_effective_stats-9.1.sql.sample
1 /*
2  * If you want the statistics of per-relation or per-column, please modify
3  * nspname, relname, and attname in 'WHERE' clause.
4  */
5
6 BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
7 /*
8  * If you want to chage the output file name, please modify the following name.
9  */
10 \o export_stats.dmp
11
12 COPY (SELECT n2.nspname,
13              cl.relname,
14              r.relpages,
15              r.reltuples,
16              r.curpages,
17              r.last_analyze,
18              r.last_autoanalyze,
19              COALESCE(a.attname, ''),
20              n1.nspname AS schemaname_of_atttype,
21              t.typname,
22              a.atttypmod,
23              co.stainherit,
24              co.stanullfrac,
25              co.stawidth,
26              co.stadistinct,
27              co.stakind1,
28              co.stakind2,
29              co.stakind3,
30              co.stakind4,
31              co.staop1,
32              co.staop2,
33              co.staop3,
34              co.staop4,
35              co.stanumbers1,
36              co.stanumbers2,
37              co.stanumbers3,
38              co.stanumbers4,
39              co.stavalues1,
40              co.stavalues2,
41              co.stavalues3,
42              co.stavalues4
43         FROM dbms_stats.column_stats_effective co
44         JOIN pg_attribute a
45           ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
46         JOIN pg_type t
47           ON a.atttypid = t.oid
48         JOIN pg_namespace n1
49           ON t.typnamespace = n1.oid
50        RIGHT JOIN dbms_stats.relation_stats_effective r
51           ON co.starelid = r.relid
52         JOIN pg_catalog.pg_class cl
53           ON r.relid = cl.oid
54         JOIN pg_catalog.pg_namespace n2
55           ON cl.relnamespace = n2.oid
56        -- WHERE n2.nspname = 'public'
57        -- AND cl.relname = 'test'
58        -- AND a.attname = 'id'
59        ORDER BY starelid, staattnum)
60 TO STDOUT
61 (FORMAT 'binary');
62 \o
63 COMMIT;