1 -- create a tablespace we can use
2 CREATE TABLESPACE testspace LOCATION '@testtablespace@';
4 -- create a schema we can use
5 CREATE SCHEMA testschema;
8 CREATE TABLE testschema.foo (i int) TABLESPACE testspace;
9 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
10 where c.reltablespace = t.oid AND c.relname = 'foo';
12 INSERT INTO testschema.foo VALUES(1);
13 INSERT INTO testschema.foo VALUES(2);
15 -- tables from dynamic sources
16 CREATE TABLE testschema.asselect TABLESPACE testspace AS SELECT 1;
17 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
18 where c.reltablespace = t.oid AND c.relname = 'asselect';
20 PREPARE selectsource(int) AS SELECT $1;
21 CREATE TABLE testschema.asexecute TABLESPACE testspace
22 AS EXECUTE selectsource(2);
23 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
24 where c.reltablespace = t.oid AND c.relname = 'asexecute';
27 CREATE INDEX foo_idx on testschema.foo(i) TABLESPACE testspace;
28 SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
29 where c.reltablespace = t.oid AND c.relname = 'foo_idx';
31 -- let's try moving a table from one place to another
32 CREATE TABLE testschema.atable AS VALUES (1), (2);
33 CREATE UNIQUE INDEX anindex ON testschema.atable(column1);
35 ALTER TABLE testschema.atable SET TABLESPACE testspace;
36 ALTER INDEX testschema.anindex SET TABLESPACE testspace;
38 INSERT INTO testschema.atable VALUES(3); -- ok
39 INSERT INTO testschema.atable VALUES(1); -- fail (checks index)
40 SELECT COUNT(*) FROM testschema.atable; -- checks heap
42 -- Will fail with bad path
43 CREATE TABLESPACE badspace LOCATION '/no/such/location';
46 CREATE TABLE bar (i int) TABLESPACE nosuchspace;
49 DROP TABLESPACE testspace;
51 DROP SCHEMA testschema CASCADE;
54 DROP TABLESPACE testspace;