I'm Newbie in postgres. I wrote a function, which insert into table a data by portions(because there is too much data in the source table to do it all at once) from another table:
CREATE OR REPLACE FUNCTION data_load(p_src_schema character varying, p_src_tab character varying,p_tgt_schema character varying, p_tgt_tab character varying)
RETURNS void AS
$BODY$
DECLARE
table_rec record;
BEGIN
FOR table_rec IN
SELECT otchdor, descr
FROM otchdor
ORDER BY otchdor
loop
insert into p_tgt_schema||'.'||p_tgt_tab
select from p_src_schema||'.'||p_src_tab
where otchdor = table_rec.otchdor;
end loop;
return;
END;
$BODY$
LANGUAGE plpgsql
;
got SQL Error [42601]: ERROR: syntax error at or near "||"
How correctly concat schema and table names at query? Where did I go wrong?
use: PostgreSQL 9.4.24 (Greenplum Database 6.14.0 build commit:Open Source) on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 6.4.0, 64-bit