Reputation: 2617
I want to know WHERE to write stored procedures in PostgreSQL? I mean not how to write but the very basic thing where to write, where to go if I want to write one?
Is it written just like query or in some different sort of file? I am fairly new to postgresql So please explain as much as possible
Upvotes: 4
Views: 9063
Reputation: 29
You need to open pgAdmin application which you need to install if you do not have it.
Then you need click on this button as I have marked and then a query editor will appear at right side. You will write your query or stored procedure or functions here in this query editor.
See the screenshot attached :
Upvotes: 0
Reputation:
Just use any text editor to create a (SQL) file containing the necessary CREATE FUNCTION statement.
Then run that file using psql.
As an alternative you can use a GUI tool like pgAdmin or something similar (Squirrel, DbVisualizer, SQL Workbench/J, ...) where you have the editor "built-in" You can directly run the statement that you edit against the database.
Upvotes: 4
Reputation: 13750
Use the CREATE FUNCTION... command in whatever your prefered PSQL manager is.
Something like this (psuedo SQL):
CREATE OR REPLACE FUNCTION
MyProc(text, text)
RETURNS
void
AS
$delimiter$
INSERT INTO MyTable (text_val_1, text_val_2)
VALUES ($1, $2);
$delimiter$
LANGUAGE SQL;
More info can be found here:
http://www.day32.com/MySQL/Meetup/Presentations/postgresql_stored_procedures.pdf
Upvotes: 3