File: squeeze.sql

package info (click to toggle)
pg-squeeze 1.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 416 kB
  • sloc: ansic: 4,408; sql: 679; python: 314; makefile: 21; sh: 15
file content (34 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
CREATE EXTENSION pg_squeeze;

CREATE TABLE a(i int PRIMARY KEY, j int);

INSERT INTO a(i, j)
SELECT x, x
FROM generate_series(1, 10) AS g(x);

-- The trivial case.
SELECT squeeze.squeeze_table('public', 'a', NULL);

SELECT * FROM a;

-- Clustering by index.
CREATE INDEX a_i_idx_desc ON a(i DESC);
SELECT squeeze.squeeze_table('public', 'a', 'a_i_idx_desc');
SELECT * FROM a;

-- Involve TOAST.
CREATE TABLE b(i int PRIMARY KEY, t text);
INSERT INTO b(i, t)
SELECT x, repeat(x::text, 1024)
FROM generate_series(1, 10) AS g(x) GROUP BY x;
SELECT reltoastrelid > 0 FROM pg_class WHERE relname='b';
-- Copy the data into another table so we can check later.
CREATE TABLE b_copy (LIKE b INCLUDING ALL);
INSERT INTO b_copy(i, t) SELECT i, t FROM b;
-- Squeeze.
SELECT squeeze.squeeze_table('public', 'b', NULL);
-- Compare.
SELECT b.t = b_copy.t
FROM   b, b_copy
WHERE  b.i = b_copy.i;