Question

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>
Was it helpful?

Solution

Just modify the last line from:

 $$ LANGUAGE plpgsql;

To

 $total$ LANGUAGE plpgsql;

You can call your function by

Select testFunc();

Create function documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top