检查 Postgres (plpgsql) 中是否存在序列 [英] Check if sequence exists in Postgres (plpgsql)
本文介绍了检查 Postgres (plpgsql) 中是否存在序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在一个存储过程中测试一个序列是否已经存在.
I'm trying to test, within a stored procedure, whether a sequence already exists.
IF EXISTS SEQUENCE seq_name
RAISE EXCEPTION 'sequence % already exists!', seq_name
END IF;
我尝试了上面代码片段的几种变体,但都没有运气.我一定给 Google 提供了错误的术语,因为我似乎找不到有关该主题的任何内容.任何帮助表示赞赏!
I have tried several variations of the snippet above without luck. I must be giving Google the wrong terms because I can't seem to find anything on the topic. Any help is appreciated!
推荐答案
您应该可以查询 pg_class 表以查看 relname 是否存在.
You should be able query the pg_class table to see if the relname exists.
IF EXISTS (SELECT 0 FROM pg_class where relname = '<my sequence name here>' )
THEN
--stuff here
END IF;
这篇关于检查 Postgres (plpgsql) 中是否存在序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文