SQL-standard function body 在定义的时parse,并已expression nodes形式储存在pg_proc.prosqlbody字段, 因此在执行的时候不需要再次被parse. 由于在执行时不parse, 因此不支持多态的参数
1 2 3 4 5 6
However, this form does not support polymorphic arguments, because there isno more parse analysis done at calltime The function body is parsed at function definition timeand stored as expression nodes in a new pg_proc column prosqlbody. So at run time, no further parsing is required.
例子1
1 2 3 4
CREATEor replaceFUNCTIONadd(a integer, b integer) RETURNSintegeras $$ select a + b; $$LANGUAGESQL;
例子2
1 2 3
CREATEFUNCTIONadd(a integer, b integer) RETURNSinteger LANGUAGESQL RETURN a + b;
例子3
1 2 3 4 5 6
CREATEorreplacePROCEDURE insert_data(a integer, b integer) LANGUAGESQL as $$ INSERTINTO tbl VALUES (a); INSERTINTO tbl VALUES (b); $$;
例子4
1 2 3 4 5 6
CREATEPROCEDURE insert_data(a integer, b integer) LANGUAGESQL BEGIN ATOMIC INSERTINTO tbl VALUES (a); INSERTINTO tbl VALUES (b); END;
duplicate function body
1 2 3 4
CREATEFUNCTION functest_S_xxx(x int) RETURNSint LANGUAGESQL AS $$SELECT x * 2 $$ RETURN x * 3;