Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit PostgreSQL stored procedure?

I'm slowly moving from MSSQL to PostgreSQL.

In MSSQL I could call editing of already saved procedure or function, and the administration shell (SQL Server Management Studio) showed me procedure's text, so I did not have to store its source code somewhere in text file.

How to do the same with PostgreSQL the convenient way? I'm using pgAdmin III.

like image 868
Paul Avatar asked Mar 25 '12 14:03

Paul


People also ask

How do I edit a PostgreSQL procedure?

You must own the procedure to use ALTER PROCEDURE . To change a procedure's schema, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the procedure's schema.

How do I edit a stored procedure in SQL?

Use SQL Server Management StudioExpand Stored Procedures, right-click the procedure to modify, and then select Modify. Modify the text of the stored procedure. To test the syntax, on the Query menu, select Parse. To save the modifications to the procedure definition, on the Query menu, select Execute.


2 Answers

There're 2 clients included in the official distributions of Postgres - the CLI one psql and a GUI one pgAdmin. Both support what you want: for psql it's \ef and for pgAdmin - right-click on function, "Properties", "Code" tab.

like image 157
Milen A. Radev Avatar answered Oct 04 '22 03:10

Milen A. Radev


It's also a convenient way to edit the code and test it.

1) Extract the code of a required SQL function from pgAdmin.

2) Place the code with the function into file.sql.

3) Create a shell/bat file in the same directory with file.sql:

psql -U postgres dbname < file.sql

4) Place a shortcut for the shell/bat file into a fast panel.

5) Edit the file with your favourite text editor and push the shortcut to update the function.

like image 22
sergzach Avatar answered Oct 04 '22 03:10

sergzach