postgre drop table whose name like "test%" 根据表名 模糊删除 上面这种话sql你知道怎么写么?
###不支持 DROP
时模糊匹配。
你只能先查出来所有表名,然后挨个删除了。
SELECT DISTINCT(table_name) FROM information_schema.columns WHERE table_name LIKE 'test%';
也可以用 FOR LOOP + END LOOP
直接 SQL 里写循环,就是比较难受……
postgres=# \dt public.ex*
List of relations
Schema | Name | Type | Owner
--------+-----------+-------+-------
public | express | table | fei
public | express_2 | table | fei
(2 rows)
postgres=# select 'drop table '||schemaname||'.'||tablename||';' from pg_tables where schemaname||'.'||tablename like '%public.ex%' \gexec
DROP TABLE
DROP TABLE
postgres=# \dt public.ex*
Did not find any relation named "public.ex*".
postgres=#