EnterpriseDB: The Enterprise Postgres Company Postgres Plus Forums: The PostgreSQL Open Source Database from EnterpriseDB
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 

Create Function in pgAdmin  XML

Forum Index » Standard Server
Author Message
trexcoleman_trexcoleman

New member

Joined: 4 Jul 2010 12:26:19
Messages: 4
Offline

I have been attempting to create a function in pgAdminIII and it appears next to impossible. What am I doing wrong???
This the procedure that I've tried:

Databases -> myDatabase -> Schemas -> public ->Functions (0)
Next I right click on Functions (0)
this brings up a window which says: Refresh, New Function..., Object List Report, Grant Wizard
From list List Box I select "New Function"

A "New Function" entry window
In the "Properties tab" I enter:
Function Name
The owner
return type
language

select Definition

And enter (paste) the function definition:

CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
BEGIN
RETURN i + 1;
END;
$$ LANGUAGE plpgsql;
Then I select "OK"

I get the following error message:
pgAdminIII
An error has occurred:

ERROR: Syntax error at or near "CREATE"
LINE 2: $BODY$CREATE OR REPLACE FUNCTION increment(i integer) RETURN...
^
This is a test function, but i get the same error on the real thing.
I have also tried
CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS '
BEGIN
RETURN i + 1;
END;
' LANGUAGE 'plpgsql';

Oh and:

CREATE FUNCTION increment(i integer) RETURNS integer AS '
BEGIN
RETURN i + 1;
END;
' LANGUAGE 'plpgsql';


with the same result.
Can somebody throw out a line???




Dave_Derry

New member

Joined: 2 Sep 2010 14:23:43
Messages: 3
Offline

OK, I've never used the facility you describe, but let me take a stab at this. From the description you give of the process (In the "Properties tab" I enter: Function Name, The owner, return type, language .... select Definition), which sounds like a wizard, and the error (Syntax error at or near "CREATE" LINE 2: $BODY$CREATE OR REPLACE ), I would guess that what it expects is just the *body* of the function. Not the complete create statement. What you have pasted in is what you would enter into a query window, and what I suspect the wizard is attempting to construct.

Try pasting just the part between the opening $$ (which gets expanded to $BODY$) and the closing $$. In other words just

BEGIN
RETURN i + 1;
END;
 
Forum Index » Standard Server
Go to:   
Powered by JForum 2.1.8 © JForum Team