模式管理 create table t2(id int, content text); CREATE TABLE teledb dt t2 List of relations Schema Name Type Owner +++ public t2 table teledb (1 row) 由于没有teledb模式,所以表默认放到了public模式下 创建teledb模式后再次建表,表建到了teledb模式下 teledb create schema teledb; CREATE SCHEMA teledb create table t3(id int, content text); CREATE TABLE teledb dt t3 List of relations Schema Name Type Owner +++ teledb t3 table teledb (1 row) 指定表位于某个模式下,不同模式下表名可以相同。在public模式下创建t3表 plaintext teledb create table public.t3(id int, content text); CREATE TABLE teledb dt public.t3 List of relations Schema Name Type Owner +++ public t3 table teledb (1 row) 同名的表查询时,没有指定shema时,始终只会查到前面模式的表数据。 plaintext 插入数据到public.t3表 teledb insert into public.t3 values(1,'test'); INSERT 0 1 由于teledb模式在第一顺位,且存在同名表,所以始终是teledb模式下的空表 teledb select from t3; id content + (0 rows) 指定public模式去查询可以查到插入的数据 teledb select from public.t3; id content + 1 test (1 row) 访问不在搜索路径的对象时,需要写全路径。 plaintext teledb create table test1.t4 (id int, name char); CREATE TABLE teledb select from t4; ERROR: relation "t4" does not exist LINE 1: select from t4; ^ teledb