I am trying to migrate data from one table to another in postgresql via record but it throws error when null values in insert statement
ERROR: syntax error at or near "," LINE 1: ...s Promo",,<ht...
QUERY: insert into site_target values (100001,"2024-07-10 17:45:16.785991+00","2024-07-10 17:45:16.786007+00",100001,,1,1,0,"Monday to Friday 10AM-6PM",,0,0,0,0,0,,,0,,,,) CONTEXT: PL/pgSQL function data_movement_ref4(character varying,character varying,timestamp without time zone,timestamp without time zone) line 29 at EXECUTE SQL state: 42601
create or replace procedure data_movement_ref4(source_table in varchar, target_table in varchar, p_minimum_date in timestamp, p_end_date in timestamp )
language plpgsql
as $$
declare lv_string character varying(3000);
v_sql character varying(3000);
loop_rec record; rec1 record;
cnt int;
c_cursor refcursor;
p_min_dt timestamp;
p_end_dt timestamp;
begin
raise notice '%',p_minimum_date ;
v_sql:='insert into '||target_table||' values ';
open c_cursor for execute 'select * from '||source_table|| ';';
loop
fetch c_cursor into loop_rec;
exit when not found;
execute v_sql|| loop_rec;
raise notice '%',loop_rec ;
cnt := cnt+1;
if cnt = 10000 then
commit;
end if;
end loop;
close c_cursor;
end;
$$
New contributor
pari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.