https://blog.youkuaiyun.com/kmblack1/article/details/78398602
速度最快,9.4或更高版本首选这个函数 可以判断临时表
if( to_regclass('test') is null ) then 你的代码 end if;
-----------------------------------------------------
方法一: pg_class 不可以判断临时表
if( (select 1 from pg_class where relname='test'::name and relkind='r') is null ) then /*你的代码*/ end if;
----或
select count(*) from pg_class where relname = 'tablename';
方法二:information_schema 可以判断临时表
if( (select 1 from information_schema.tables
where table_schema = 'public' and table_name = 'test') is null )
then /*你的代码*/ end if;
----或
select count(*) from information_schema.tables
where table_schema='public'
and table_type='BASE TABLE'
and table_name='tablename';
方法三:pg_tables catalog
if( (select 1 from pg_tables where schemaname = 'public' and tablename = 'test') is null )
then /*你的代码*/ end if;