PostgreSQL 可以在过程中声明过程吗?
create or replace procedure procedure_1()
language plpgsql
as $$
declare
precedure procedure_2()
begin
select 1;
end
begin
select 1;
end; $$
有什么方法可以在 procedure_1()
中声明 procedure_2()
吗?
create or replace procedure procedure_1()
language plpgsql
as $
declare
precedure procedure_2()
begin
select 1;
end
begin
select 1;
end; $
Is there any way to declare a procedure_2()
inside procedure_1()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是 - 如果“声明”是指“创建”。
db<>fiddle 这里
你只需正确引用。请参阅:
函数和过程不是“声明”,但是 在 Postgres 中“创建”。这会在数据库中创建一个对象,然后所有具有适当权限的人都可以看到并使用该对象。 (不仅仅是过程或事务本地的临时对象。)
但是,您可以使用此“hack”创建一个“临时”函数或过程 - 如果这就是您的想法:
Yes - if by "declare" you mean "create".
db<>fiddle here
You just have to get the quoting right. See:
Functions and procedures are not "declared", but "created" in Postgres. That creates an object in the database which is then visible and usable by all with appropriate permissions. (Not just a temporary object local to the procedure or transaction.)
You can, however, create a "temporary" function or procedure, with this "hack" - if that's what you had in mind: