I'm trying to create a function in plpgsql in Postgres that receives null parameters as default.
Example:
create or REPLACE function spinserir_0200(
p_id_entidade integer DEFAULT null::int ,
p_cod_item bigint DEFAULT NULL::bigint,
p_descr_item text DEFAULT NULL::text,
p_cod_barra bigint default NULL::BIGINT,
p_cod_ant_item integer DEFAULT NULL::integer,
p_unid_inv text DEFAULT NULL::text,
p_tipo_item text DEFAULT '00',
p_cod_ncm integer DEFAULT NULL::integer,
p_ex_ipi integer DEFAULT NULL::integer,
p_cod_gen integer DEFAULT NULL::integer,
p_cod_lst integer DEFAULT NULL::integer,
p_aliq_icms text DEFAULT NULL::text
) returns integer
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO tb_produtos
(
ID_ENTIDADE,
COD_ITEM ,
DESCR_ITEM,
COD_BARRA,
COD_ANT_ITEM,
UNID_INV,
TIPO_ITEM,
COD_NCM,
EX_IPI,
COD_GEN,
COD_LST,
ALIQ_ICMS
)
VALUES
(
p_ID_ENTIDADE,
p_COD_ITEM,
p_DESCR_ITEM,
p_COD_BARRA,
p_COD_ANT_ITEM,
p_UNID_INV,
p_TIPO_ITEM,
p_COD_NCM,
p_EX_IPI,
p_COD_GEN,
p_COD_LST,
p_ALIQ_ICMS
);
END IF;
RETURN 1;
END ;
$$;
Even though I declare the parameters this way it gives error:
p_id_entidade integer DEFAULT null::int
It displays the following error:
( p_id_entidade => unknown) does not exist.
But if I pass this way the function call:
p_id_entidade:= null::int
It accepts, but I would like to not need to cast the call.
Is there a way to cast the function declaration?