-- utility functions currently not supported here CREATEPROCEDURE ptestx()
LANGUAGE SQL
BEGIN ATOMIC CREATETABLE x (a int);
END;
CREATEPROCEDURE ptest2()
LANGUAGE SQL AS $$ SELECT5;
$$;
CALL ptest2();
-- nested CALL
TRUNCATE cp_test;
CREATEPROCEDURE ptest3(y text)
LANGUAGE SQL AS $$ CALL ptest1(y); CALL ptest1($1);
$$;
CALL ptest3('b');
SELECT * FROM cp_test;
-- output arguments
CREATEPROCEDURE ptest4a(INOUT a int, INOUT b int)
LANGUAGE SQL AS $$ SELECT1, 2;
$$;
CALL ptest4a(NULL, NULL);
CREATEPROCEDURE ptest4b(INOUT b int, INOUT a int)
LANGUAGE SQL AS $$ CALL ptest4a(a, b); -- error, not supported
$$;
-- we used to get confused by a single output argument that is composite CREATEPROCEDURE ptest4c(INOUT comp int8_tbl)
LANGUAGE SQL AS $$ SELECT ROW(1, 2);
$$;
CALL ptest4c(NULL);
DROPPROCEDURE ptest4a, ptest4c;
-- named and default parameters
CREATEORREPLACEPROCEDURE ptest5(a int, b text, c intdefault100)
LANGUAGE SQL AS $$ INSERTINTO cp_test VALUES(a, b); INSERTINTO cp_test VALUES(c, b);
$$;
TRUNCATE cp_test;
CALL ptest5(10, 'Hello', 20); CALL ptest5(10, 'Hello'); CALL ptest5(10, b => 'Hello'); CALL ptest5(b => 'Hello', a => 10);
SELECT * FROM cp_test;
-- polymorphic types
CREATEPROCEDURE ptest6(a int, b anyelement)
LANGUAGE SQL AS $$ SELECTNULL::int;
$$;
CALL ptest6(1, 2);
CREATEPROCEDURE ptest6a(inout a anyelement, out b anyelement)
LANGUAGE SQL AS $$ SELECT $1, $1;
$$;
CALL ptest6a(1, null); CALL ptest6a(1.1, null);
CREATEPROCEDURE ptest6b(a anyelement, out b anyelement, out c anyarray)
LANGUAGE SQL AS $$ SELECT $1, array[$1];
$$;
CREATEPROCEDURE ptest9(OUT a int)
LANGUAGE SQL AS $$ INSERTINTO cp_test VALUES (1, 'a'); SELECT1;
$$;
-- standard way to do a call: CALL ptest9(NULL); -- you can write an expression, but it's not evaluated CALL ptest9(1/0); -- no error -- ... and it had better match the type of the parameter CALL ptest9(1./0.); -- error
-- check named-parameter matching CREATEPROCEDURE ptest10(OUT a int, IN b int, IN c int)
LANGUAGE SQLAS $$ SELECT b - c $$;
CALL ptest10(null, 7, 4); CALL ptest10(a => null, b => 8, c => 2); CALL ptest10(null, 7, c => 2); CALL ptest10(null, c => 4, b => 11); CALL ptest10(b => 8, c => 2, a => 0);
CREATEPROCEDURE ptest11(a OUTint, VARIADIC b int[]) LANGUAGE SQL AS $$ SELECT b[1] + b[2] $$;
CALL ptest11(null, 11, 12, 13);
-- check resolution of ambiguous DROP commands
CREATEPROCEDURE ptest10(IN a int, IN b int, IN c int)
LANGUAGE SQLAS $$ SELECT a + b - c $$;
\df ptest10
dropprocedure ptest10; -- fail dropprocedure ptest10(int, int, int); -- fail
begin; dropprocedure ptest10(outint, int, int);
\df ptest10 dropprocedure ptest10(int, int, int); -- now this would work
rollback;
begin; dropprocedure ptest10(inint, int, int);
\df ptest10 dropprocedure ptest10(int, int, int); -- now this would work
rollback;
-- various error cases
CALL version(); -- error: not a procedure CALL sum(1); -- error: not a procedure
CREATEPROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERTINTO cp_test VALUES (1, 'a') $$; CREATEPROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERTINTO cp_test VALUES (1, 'a') $$; CREATEPROCEDURE ptestx(a VARIADIC int[], b OUTint) LANGUAGE SQL AS $$ SELECT a[1] $$; CREATEPROCEDURE ptestx(a intDEFAULT42, b OUTint) LANGUAGE SQL AS $$ SELECT a $$;
ALTERPROCEDURE ptest1(text) STRICT; ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function ALTERPROCEDURE cp_testfunc1(int) VOLATILE; -- error: not a procedure ALTERPROCEDURE nonexistent() VOLATILE;
DROP FUNCTION ptest1(text); -- error: not a function DROPPROCEDURE cp_testfunc1(int); -- error: not a procedure DROPPROCEDURE nonexistent();
-- privileges
CREATE USER regress_cp_user1; GRANTINSERTON cp_test TO regress_cp_user1; REVOKE EXECUTE ONPROCEDURE ptest1(text) FROM PUBLIC; SET ROLE regress_cp_user1; CALL ptest1('a'); -- error
RESET ROLE; GRANT EXECUTE ONPROCEDURE ptest1(text) TO regress_cp_user1; SET ROLE regress_cp_user1; CALL ptest1('a'); -- ok
RESET ROLE;
-- ROUTINE syntax
ALTER ROUTINE cp_testfunc1(int) RENAMETO cp_testfunc1a; ALTER ROUTINE cp_testfunc1a RENAMETO cp_testfunc1;
ALTER ROUTINE ptest1(text) RENAMETO ptest1a; ALTER ROUTINE ptest1a RENAMETO ptest1;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.