回答

收藏

PostgreSQL:是否存在检查模式?

技术问答 技术问答 593 人阅读 | 0 人回复 | 2023-09-14

我需要动态创建、管理和删除模式。如果我想创建一个现有的模式,我想删除它,并以指定的方式重新创建它。如何检查我的Postgres
! J5 l) Q- f6 |1 r上述模式是否存在于服务器上?. Y; {6 W. W# R. j" P) s5 g
目前,我正在这样做:
; x  R/ F5 y# g* f! u- Xselect exists (select * from pg_catalog.pg_namespace where nspname = 'schemaname');但我认为可能还有另一种方法……这是查询Postgres是否存在特定模式的“正确”方法吗?
, n) Z, @0 e% b                                                               
* G! _+ x/ j- Z5 }" a# {    解决方案:                                                                / o: \; x9 w/ ~  B; n
                                                                以下查询将告诉您模式是否存在。2 a5 J- o! d6 P
SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'name
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则