4

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

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

0

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 :

pgAdmin : Query Editor to write queries

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.