Last active
November 5, 2019 17:17
-
-
Save NielsLiisberg/295713ad2203a2939253e171ba11789b to your computer and use it in GitHub Desktop.
SQL compund statement using FOR loop and writing JSON to the IFS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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