0 votes
549 views
by datalab (20.7k points) | 549 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://
by pnorris (260 points)
edited by 14

418 questions

435 answers

440 comments

637 users

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

Categories