sql server - Stored procedure in T-SQL transform to PostgreSQL -
i have stored procedure writen in t-sql , want make postgresql i'm not familiar postgresql.
my stored procedure this:
create procedure usp_insert_allocated_time @fld_project_id int, @fld_allocated_time int declare @project int; set @project = @fld_project_id; declare @allocated int; declare @time int; begin set @time = (select sum(fld_allocated_time) dbo.tbl_project_timesheet fld_project_id =@project) set @allocated = (select fld_allocated_days dbo.tbl_project fld_id = @project); if @allocated > @time begin insert dbo.tbl_project_timesheet(fld_project_id,fld_allocated_time) values(@fld_project_id,@fld_allocated_time); end else print 'not ok'; end
and have this, on line 10 error:
error: invalid input syntax integer: "293.00"
sql state: 22p02
context: pl/pgsql function "sa_prj".usp_add_timesheet_record_new(integer,integer,numeric,numeric,character varying,character varying) line 10 @ assignment
create or replace function "sa_prj".usp_add_timesheet_record_new(p_uid integer, p_project_id integer, p_allocated_time numeric, p_achieved_time numeric, p_task_desc character varying, p_obs character varying) returns void $body$ declare alloc_id integer; declare project integer; declare allocated integer; declare allocated_time integer; begin project := p_project_id; allocated_time := (select sum(fld_allocated_time) "sd_prj".tbl_project_timesheet fld_project_id = project); allocated := (select fld_allocated_days "sd_prj".tbl_project fld_id = project); if not "sa_adm".usp_check_permission(p_uid, 'sa_prj', 'usp_add_timesheet_record') raise exception 'user id % no have permission!', p_uid; end if; select fld_id alloc_id "sd_prj".tbl_project_allocation fld_emp_id = p_uid , fld_project_id = p_project_id; begin if (allocated > allocated_time) insert "sd_prj".tbl_project_timesheet(fld_emp_id, fld_project_id, fld_is_allocated,fld_allocated_time, fld_achieved_time, fld_task_desc, fld_obs) values (p_uid,p_project_id,coalesce(alloc_id,0), p_allocated_time, p_achieved_time,p_task_desc, p_obs); else raise notice 'not ok!!'; end if; end; end $body$ language plpgsql volatile cost 100;
it's more complex version in postgresql want.
you don't give enough information try , fix problem, error message pretty descriptive. trying put 293.00 integer. here can reproduce:
do $$ declare int; begin := 293.00; raise notice 'i=%', i; end $$;
this raise:
error: invalid input syntax integer: "293.00" sql state: 22p02 context: pl/pgsql function inline_code_block line 6 @ assignment
you need change variable same datatype data trying assign it. example:
do $$ declare numeric(5, 2); begin := 293.00; raise notice 'i=%', i; end $$;
this works , outputs:
notice: i=293.00 query returned no result in 14 ms.
Comments
Post a Comment