表空间在pg_tables中显示为null

时间:2019-07-08 13:50:17

标签: postgresql

我通过显式传递表空间名称来创建表。但是在检入pg_tables和其他pg_表时

Create table test1c (Id integer, name varchar(10)) tablespace testts;

select * 
from pg_tables 
where tablename='test1c';

它应该显示表空间名称,但显示为空

1 个答案:

答案 0 :(得分:0)

默认表空间将不会显示在pg_tables.tablespace

Quote from the manual

  

包含表的表空间名称(如果数据库默认为空,则为空

(重点是我的)


如果要查看实际的表空间,则需要在查询中包括pg_database

select t.schemaname, t.tablename, 
       coalesce(t.tablespace, ts.default_tablespace) as tablespace
from pg_tables t
  cross join (
     select ts.spcname as default_tablespace
     from pg_database d
       join pg_tablespace ts on ts.oid = d.dattablespace
      where d.datname = current_database()
   ) ts
where tablename = 'test1c'
  and schemaname = 'public';
相关问题