Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 913
Jeremiah Peschka Avatar asked Apr 02 '10 22:04

Jeremiah Peschka


People also ask

Can we run Plsql in PostgreSQL?

PL/pgSQL comes with PostgreSQL by default. The user-defined functions and stored procedures developed in PL/pgSQL can be used like any built-in functions and stored procedures. PL/pgSQL inherits all user-defined types, functions, and operators.

Which function is used to EXECUTE query in PostgreSQL?

To do this in PL/pgSQL, use the PERFORM statement: PERFORM query ; This executes query and discards the result. Write the query the same way you would write an SQL SELECT command, but replace the initial keyword SELECT with PERFORM .

What does := mean in PostgreSQL?

:= is the assignment operator in PL/pgSQL.


2 Answers

Postgres 9

DO $$  -- declare BEGIN   /* pl/pgsql here */ END $$; 
like image 70
chotchki Avatar answered Sep 22 '22 10:09

chotchki


No, not yet. Version 9.0 (still alpha) will have this option (do), you a have to wait until it's released.

like image 27
Frank Heikens Avatar answered Sep 24 '22 10:09

Frank Heikens