0

I am creating a function in my PostgreSQL but I'm getting this syntax error and I ran out of ideas what could be wrong... Please assist.

CREATE OR REPLACE FUNCTION get_docName(IN p_docId_id bigint) 
RETURNS TABLE(name varchar) AS
$BODY$

begin
RETURN query SELECT name * FROM (documents) where id=p_docId
end;
$BODY$
LANGUAGE sql STABLE;
ALTER FUNCTION public.get_documents(IN bigint)
  OWNER TO postgres;

Errors:

ERROR:  SyntaxError at „RETURN“
LINE 8: RETURN query SELECT * FROM (
        ^
********** Error **********

ERROR: SyntaxError at „RETURN“
SQL state: 42601
Character: 173

1 Answer 1

2

You're trying to use PL/PgSQL syntax in an SQL function. You also forgot the semicolon on the end of the SELECT.

Declare it LANGUAGE plpgsql. Or, as the function is so trivial, just turn it into valid sql function syntax by replacing the body with:

$BODY$
SELECT name * FROM (documents) where id=p_docId;
$BODY$

though the SQL statement its self is also invalid - name *?

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

1 Comment

@Jacob That's because that SQL is invalid. What are you trying to write? name * FROM ... makes no sense.

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.