pktCoder
pktCoder

Reputation: 1115

syntax error when running postgresql function/stored procedure

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!

Upvotes: 0

Views: 703

Answers (1)

Pavel Stehule
Pavel Stehule

Reputation: 45750

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.

Upvotes: 3

Related Questions