I wrote a function in PostgreSQL with a parameter, where I want to insert the parameter value in a database table. The script executes fine but when I call the function I got an error message:
CREATE OR REPLACE FUNCTION sp_load_purchase_order(x int)
RETURNS void AS
$$
declare var_val char;
begin
var_val='p'+i;
insert into purchase_order(
create_uid,
create_date,
write_date,
write_uid,
journal_id,
date_order,
partner_id,
amount_untaxed,
location_id,
company_id,
amount_tax,
state,
pricelist_id,
warehouse_id,
payment_term_id,
amount_total,
name,
invoice_method,
shipped,
minimum_planned_date
)
values(1,now(),now(),1,13,now(),17,1.00,12,1,0.00,'draft',2,1,3,1.00
,var_val,'order','f' ,now()
);
end;
$$
LANGUAGE 'plpgsql';
Error message:
ERROR: column "i" does not exist
LINE 1: SELECT 'p'+i
^
QUERY: SELECT 'p'+i
CONTEXT: PL/pgSQL function sp_load_purchase_order(integer) line 5 at assignment
********** Error **********
ERROR: column "i" does not exist
SQL state: 42703
Context: PL/pgSQL function sp_load_purchase_order(integer) line 5 at assignment
Please help me point out the problem.