Saving results to virtual storage using Storage Manager
Now we want to save the results from the a query to our virtual storage space. By putting the query in a try-block we are able to trap errors when executing the query.
response = queryClient.query (token, adql=query, fmt='csv',
except Exception as e:
# Handle any errors in the query. By running this cell multiple times with the same
# output file, or by using a bogus SQL statement, you can view various error messages.
if response is not None:
print (response) # print the response
Saving results to virtual storage using the datalab command
Now we'll save the results to our virtual storage space as a file. Note that the initial login above has saved our identity token which will be passed automatically with the query. Afterward, we'll list the virtual storage space to confirm the file was saved.
# Login again to access Virtual Storage
!datalab login user=demo00 password=password
!datalab query out='vos://smash_mags.csv' \
sql='select id,gmag,rmag,imag from smash_dr1.object limit 10000'
!datalab ls name=vos://