我只有一个名为“testDB”的数据库。在命令行中:1)
psql testDB
2)尽可能简单地创建一个函数:
CREATE or replace FUNCTION testFun()
RETURNS integer AS $total$
declare
total integer;
BEGIN
SELECT count(*) into total FROM "Run";
RETURN total;
END;
$$ LANGUAGE plpgsql;
我不知道它是干什么用的?:$$ LANGUAGE plpgsql; 但在某些例子中。
所以我把它复制到命令行。
毕竟什么都没有发生。
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$>
注意:
testDB=>
testDB->
testDB>