⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tablespace.source

📁 postgresql8.3.4源码,开源数据库
💻 SOURCE
字号:
-- create a tablespace we can useCREATE TABLESPACE testspace LOCATION '@testtablespace@';-- create a schema we can useCREATE SCHEMA testschema;-- try a tableCREATE TABLE testschema.foo (i int) TABLESPACE testspace;SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c    where c.reltablespace = t.oid AND c.relname = 'foo'; relname |  spcname  ---------+----------- foo     | testspace(1 row)INSERT INTO testschema.foo VALUES(1);INSERT INTO testschema.foo VALUES(2);-- tables from dynamic sourcesCREATE TABLE testschema.asselect TABLESPACE testspace AS SELECT 1;SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c    where c.reltablespace = t.oid AND c.relname = 'asselect'; relname  |  spcname  ----------+----------- asselect | testspace(1 row)PREPARE selectsource(int) AS SELECT $1;CREATE TABLE testschema.asexecute TABLESPACE testspace    AS EXECUTE selectsource(2);SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c    where c.reltablespace = t.oid AND c.relname = 'asexecute';  relname  |  spcname  -----------+----------- asexecute | testspace(1 row)-- indexCREATE INDEX foo_idx on testschema.foo(i) TABLESPACE testspace;SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c    where c.reltablespace = t.oid AND c.relname = 'foo_idx'; relname |  spcname  ---------+----------- foo_idx | testspace(1 row)-- let's try moving a table from one place to anotherCREATE TABLE testschema.atable AS VALUES (1), (2);CREATE UNIQUE INDEX anindex ON testschema.atable(column1);ALTER TABLE testschema.atable SET TABLESPACE testspace;ALTER INDEX testschema.anindex SET TABLESPACE testspace;INSERT INTO testschema.atable VALUES(3);	-- okINSERT INTO testschema.atable VALUES(1);	-- fail (checks index)ERROR:  duplicate key value violates unique constraint "anindex"SELECT COUNT(*) FROM testschema.atable;		-- checks heap count -------     3(1 row)-- Will fail with bad pathCREATE TABLESPACE badspace LOCATION '/no/such/location';ERROR:  could not set permissions on directory "/no/such/location": No such file or directory-- No such tablespaceCREATE TABLE bar (i int) TABLESPACE nosuchspace;ERROR:  tablespace "nosuchspace" does not exist-- Fail, not emptyDROP TABLESPACE testspace;ERROR:  tablespace "testspace" is not emptyDROP SCHEMA testschema CASCADE;NOTICE:  drop cascades to table testschema.atableNOTICE:  drop cascades to table testschema.asexecuteNOTICE:  drop cascades to table testschema.asselectNOTICE:  drop cascades to table testschema.foo-- Should succeedDROP TABLESPACE testspace;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -