Postgresql: Array value must start with "{" or dimension information -


create or replace function f_old_transactions (in p_fromdate date, in p_todate date, in p_transtype varchar,in out p_cancelled boolean, out p_transaction_date date, out p_type varchar, out p_description varchar, out p_amount numeric)   returns setof record $body$  declare lrunquery text;  declare ltotalrec record; declare lbranchlist text[];  declare ltranstype text[];    begin  select ltranstype     dt.type      v_data_types dt;       ltranstype := regexp_split_to_array(p_transtype, ',');  lrunquery := 'select it.transaction_date trandate, dt.type, it.description, ita.amount, it.cancelled    import_transaction inner join import_transaction_account ita on it.import_transaction_id=ita.import_transaction_id    it.transaction_date >= ' || quote_literal(p_fromdate) || ' , it.transaction_date <= ' || quote_literal(p_todate) || ' , dt.type = any(' || quote_literall(p_transtype) || ') and';  if (p_cancelled = true) lrunquery := lrunquery || ' it.cancelled = ' || quote_literal(p_cancelled) || ''; else lrunquery := lrunquery || ' it.cancelled = ' || quote_literal(p_cancelled) || ''; end if;    ltotalrec in     execute lrunquery   loop p_transaction_date := ltotalrec.trandate; p_type :=ltotalrec.type; p_description :=ltotalrec.description; p_amount :=ltotalrec.amount; p_cancelled := ltotalrec.cancelled; return next; end loop;  return ; end;   $body$ language plpgsql immutable cost 100 rows 1000; alter function  f_old_transactions(date,date,varchar,boolean) owner "compuloanpostgres";  select * f_old_transactions ('01-jan-2010','31-dec-2018','receipt cash','false') 

i'm getting error array value must start "{". array i'm trying create view v_data_type view consist of 1 column varchar type.

can please direct me issue in code is?

thank in advance

i don't think you've given enough information know what's going wrong. notably, have no idea tables should like, either in schema or content. without that, can't build test case in own db debug.

that said, noticed couple things, around ltranstype variable:

  1. you're assigning ltranstype twice. first select into it, , assign value unpacked p_transtype argument. it's not clear me want in variable.

  2. when constructing query later, include and dt.type = any(' || quote_literall(p_transtype) || '). problem p_transtype varchar argument, , you're trying access array. suspect want read and dt.type = any(' || quote_literall(ltranstype) || '), mistaken.

i'm guessing type error coming second problem, seems need reassess different variables in function intended for. luck.


Comments