Skip to content

Instantly share code, notes, and snippets.

@NielsLiisberg
Last active November 5, 2019 17:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NielsLiisberg/295713ad2203a2939253e171ba11789b to your computer and use it in GitHub Desktop.
Save NielsLiisberg/295713ad2203a2939253e171ba11789b to your computer and use it in GitHub Desktop.
SQL compund statement using FOR loop and writing JSON to the IFS
begin
declare cmd varchar(4096);
declare comma varchar(1) default '';
call qusrsys.ifs_write('/tmp/test.json' , '[');
for vl as c1 cursor for select cusnum , lstnam from qiws.qcustcdt a do
call qusrsys.ifs_append('/tmp/test.json' ,
comma concat
json_object (
'customerNumber' : CUSNUM,
'name' : LSTNAM
)
);
set comma = ',';
end for;
call qusrsys.ifs_append('/tmp/test.json' , ']');
end;
-- Which (for small file <32K ) can be written as:
call qusrsys.ifs_write('/tmp/test.json' ,
json_array((
select
json_object (
'customerNumber' : CUSNUM,
'name' : LSTNAM
)
from qiws.qcustcdt
))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment