0

Trying to perform a set of complex Postgresql DB operations by using function, but even a simple function gets me error:

ERROR:  syntax error at or near "text"
LINE 3:    tmp text := info;
               ^

Here is SQL

CREATE or REPLACE FUNCTION createme (info text) RETURNS text AS $$
DECLARE 
   tmp text := info;
BEGIN
   select :tmp
end
$$ LANGUAGE SQL;

Any idea why? Thx!

1 Answer 1

3

You procedure is not in SQL language, but it is in plpgsql language.

CREATE or REPLACE FUNCTION createme (info text) RETURNS text AS $$
DECLARE 
  tmp text := info;
BEGIN
  RETURN tmp;
end
$$ LANGUAGE plpgsql;

SELECT :tmp is nonsense in this content. Functions returns a value with command RETURN - it is similar to any other environments.

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

1 Comment

Thanks @pavel-stehule !

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.