Plpgsql function error at or near Create syntax

107 views Asked by At

I have just started using postgres and am new to the whole thing, I am using postgres version 9.6 and am trying to create a new function however I keep getting the error

ERROR: syntax error at or near "CREATE"
LINE 6: CREATE OR REPLACE FUNCTION time_passed(created text)

my function is this

CREATE OR REPLACE FUNCTION time_passed(created text)
  RETURNS text AS 

BEGIN

created :='Now';
RETURN created;

END;
$$ LANGUAGE plpgsql

What could be wrong with the Create syntax?

1

There are 1 answers

0
Mureinik On BEST ANSWER

You're missing the opening $$ to match the closing ones:

CREATE OR REPLACE FUNCTION time_passed(created text)
RETURNS text AS $$
-- Here --------^
BEGIN
    created :='Now';
    RETURN created;
END;
$$ LANGUAGE plpgsql