How to assign default value to following type of Oracle statement into PostgreSQL 9.3?
CREATE OR REPLACE FUNCTION(....
...
DECLARE
v_var Table01.column01%TYPE := 'SLOW';
BEGIN
...
...
END;
How to assign default value to following type of Oracle statement into PostgreSQL 9.3?
CREATE OR REPLACE FUNCTION(....
...
DECLARE
v_var Table01.column01%TYPE := 'SLOW';
BEGIN
...
...
END;
Postgres allows to provide parameter defaults, which kick in for missing parameters in the function call. Only allowed for parameters at the end of the list.
Example:
CREATE OR REPLACE FUNCTION foo (
param1 int
, v_char tbl01.col01%TYPE DEFAULT 'foo')
...
-- no need to DECLARE anything else.
BEGIN
...
Syntactical shortcut would be v_char tbl01.col01%TYPE
=
'foo'
.
Call:
SELECT * FROM foo(1, 'bar');
SELECT * FROM foo(1); -- Param default kicks in
Details in the manual.