Cast parameter Postgresql function DEFAULT null::int

Asked

Viewed 242 times

1

I am trying to create a plpgsql function 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 ;
$$;

But even if I declare the parameters this way it gives error :

p_id_entidade integer DEFAULT null::int 

I understand that if it was null the parameter it would already cast for type int, but it is not doing.

It presents the following error:

( p_id_entidade => unknown) does not exist.

But if I pass this way the function call:

 p_id_entidade:= null::int

He accepts, but I wish I didn’t have to cast the call.

There is how to cast in function declaration?

1 answer

0

By default if you do not put the "Default" it will already consider as default null friend... no need to put the "default null"...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.