select max(f)
from (with t as (select e.patlabexamid,
e.patlabexamname,
e.patlabexamdate,
f.patlabexamid,
f.patlabexamfilename,
replace(substring(f.patlabexamfilename from '\..*'), '.', '') as file_extention,
fol.path,
f.documentid,
format(
'copy (select encode(s.documentblob, ''hex'') from documents s where s.documentid = %s) to ''%s''',
f.documentid, fol.path) as query
from g_pat_lab_exam_files f
join g_pat_lab_exams e on f.patlabexamid = e.patlabexamid
join lateral ( select '/j_storage/' ||
to_char(e.patlabexamdate, 'YYYY_MM/') || f.documentid || '.hex'
as path
from global_settings s
where globalsettingid = 330) as fol on true
where f.file_id is null
and f.patlabexamfileid between 1 and 43000
)
select f_execute_test(query) f
from t) as t
;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter