How can I execute pl/pgsql code without creating a function?

Jeremiah Peschka picture Jeremiah Peschka · Apr 3, 2010 · Viewed 17.5k times · Source

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.

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

Answer

chotchki picture chotchki · Oct 25, 2010

Postgres 9

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