in below query when execute throws error function result type must integer because of out parameters.pls me overocme issue.
create or replace function funinsertupdateproduct(i_productid integer, t_productname text, t_productdesc text, i_brandid integer, i_varianceid integer, i_packsizeid integer, i_clientid integer, i_userid integer,out i_prodid integer ) returns void $body$ begin if exists (select 1 "product" product_id = i_productid) update "product" set "product_name" = t_productname, "product_desc" = t_productdesc, "brand_id"=i_brandid,variance_id=i_varianceid,pack_size_id=i_packsizeid product_id = i_productid; else insert "product"("product_name", "product_desc", "create_by","client_id",variance_id,brand_id,pack_size_id ) values ( t_productname, t_productdesc,i_userid,i_clientid,i_varianceid,i_brandid,i_packsizeid) returning product_id i_prodid; end if; return; end; $body$ language plpgsql volatile cost 100; alter function funinsertupdateproduct(integer, text, text, integer, integer, integer, integer, integer,integer) owner postgres;
postgres functions take getting used to. in addition being triggers , stored procedures, way handled returned values differs other languages.
in essence, out
parameters represent record being returned function. there no separate method of returning value, void
redundant . . . and, in fact, incompatible out
parameters.
the solution simple. remove returns
clause:
create or replace function funinsertupdateproduct ( i_productid integer, t_productname text, t_productdesc text, i_brandid integer, i_varianceid integer, i_packsizeid integer, i_clientid integer, i_userid integer, out i_prodid integer ) $body$ . . .
except not defining i_prodid
, equivalent to:
create or replace function funinsertupdateproduct ( i_productid integer, t_productname text, t_productdesc text, i_brandid integer, i_varianceid integer, i_packsizeid integer, i_clientid integer, i_userid integer ) returns integer $body$ . . .
Comments
Post a Comment