如何在不创建函数的情况下执行pl/pgsql代码?

问题描述:

使用SQL Server,我可以通过SQL Server Management Studio或任何其他客户端使用完整的过程逻辑来执行临时的T-SQL代码.我已经开始使用PostgreSQL,但在PGSQL需要将任何逻辑嵌入到函数中的情况下,出现了一些差异.

With SQL Server, I can execute code ad hoc T-SQL code with full procedural logic through SQL Server Management Studio, or any other client. I've begun working with PostgreSQL and have run into a bit of a difference in that PGSQL requires any logic to be embedded in a function.

是否可以在不创建执行函数的情况下执行PL/PGSQL代码?

Is there a way to execute PL/PGSQL code without creating an executing a function?

Postgres 9

Postgres 9

DO $$ 
-- declare
BEGIN
  /* pl/pgsql here */
END $$;