0 votes
541 views
asked May 28, 2017 by datalab (19,200 points) | 541 views

1 Answer

0 votes

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.

try:
    response = queryClient.query (token, adql=query, fmt='csv', 
                                  out='vos://zxmags.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.
    print (e.message)
else:
    if response is not None: 
        print (response)           # print the response
    else:
        print ("OK")

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://
answered Aug 8, 2017 by pnorris (260 points)
edited Aug 8, 2017 by pnorris

359 questions

372 answers

385 comments

2,427 users

Welcome to Data Lab Help Desk, where you can ask questions and receive answers from other members of the community.