1 -- create a tablespace we can use
2 CREATE TABLESPACE testspace LOCATION '@testtablespace@';
3 -- create a schema we can use
4 CREATE SCHEMA testschema;
6 CREATE TABLE testschema.foo (i int) TABLESPACE testspace;
7 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
8 where c.reltablespace = t.oid AND c.relname = 'foo';
14 INSERT INTO testschema.foo VALUES(1);
15 INSERT INTO testschema.foo VALUES(2);
16 -- tables from dynamic sources
17 CREATE TABLE testschema.asselect TABLESPACE testspace AS SELECT 1;
18 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
19 where c.reltablespace = t.oid AND c.relname = 'asselect';
21 ----------+-----------
25 PREPARE selectsource(int) AS SELECT $1;
26 CREATE TABLE testschema.asexecute TABLESPACE testspace
27 AS EXECUTE selectsource(2);
28 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
29 where c.reltablespace = t.oid AND c.relname = 'asexecute';
31 -----------+-----------
36 CREATE INDEX foo_idx on testschema.foo(i) TABLESPACE testspace;
37 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
38 where c.reltablespace = t.oid AND c.relname = 'foo_idx';
44 -- let's try moving a table from one place to another
45 CREATE TABLE testschema.atable AS VALUES (1), (2);
46 CREATE UNIQUE INDEX anindex ON testschema.atable(column1);
47 ALTER TABLE testschema.atable SET TABLESPACE testspace;
48 ALTER INDEX testschema.anindex SET TABLESPACE testspace;
49 INSERT INTO testschema.atable VALUES(3); -- ok
50 INSERT INTO testschema.atable VALUES(1); -- fail (checks index)
51 ERROR: duplicate key value violates unique constraint "anindex"
52 SELECT COUNT(*) FROM testschema.atable; -- checks heap
58 -- Will fail with bad path
59 CREATE TABLESPACE badspace LOCATION '/no/such/location';
60 ERROR: could not set permissions on directory "/no/such/location": No such file or directory
62 CREATE TABLE bar (i int) TABLESPACE nosuchspace;
63 ERROR: tablespace "nosuchspace" does not exist
65 DROP TABLESPACE testspace;
66 ERROR: tablespace "testspace" is not empty
67 DROP SCHEMA testschema CASCADE;
68 NOTICE: drop cascades to 4 other objects
69 DETAIL: drop cascades to table testschema.foo
70 drop cascades to table testschema.asselect
71 drop cascades to table testschema.asexecute
72 drop cascades to table testschema.atable
74 DROP TABLESPACE testspace;