문제

I`ve got only one database which name is "testDB". In command line: 1)

psql testDB

2) create a function as easies as is possible:

CREATE or replace FUNCTION testFun()
  RETURNS integer AS $total$
declare
  total integer;
BEGIN
  SELECT count(*) into total FROM "Run";
  RETURN total;
END;
 $$ LANGUAGE plpgsql;

I don`t know what it is for?: $$ LANGUAGE plpgsql; but it was in some example.

So I copied it to command line.

After all nothing happen.

user@LenovoUbuntu:~$ psql testDB 
psql (9.1.11)
Type "help" for help.

testDB=> CREATE or replace FUNCTION testFun()
testDB->   RETURNS integer AS $total$
testDB$> declare
testDB$>   total integer;
testDB$> BEGIN
testDB$>   SELECT count(*) into total FROM "Run";
testDB$>   RETURN total;
testDB$> END;
testDB$>  $$ LANGUAGE plpgsql;
testDB$> 

Pay attention on:

testDB=>
testDB->
testDB>
도움이 되었습니까?

해결책

Just modify the last line from:

 $$ LANGUAGE plpgsql;

To

 $total$ LANGUAGE plpgsql;

You can call your function by

Select testFunc();

Create function documentation

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top