Sloan Digital Sky Survey III
SkyServer DR10  
 

DR10 Help
 Start Here
 FAQ
 Glossary
 Cooking with Sloan
 Tool User Guides
 Contact Help Desk
 
 Searching SDSS-III
 SQL Tutorial
 SQL in SkyServer
 About the Database
 Table Descriptions
 Sample SQL Queries
 Schema Browser
 Searching Advice
 Query Limits
 
 Details of the Data
 Algorithms
 Data Publications
 API
Download

SDSS Command Line Query Tool

Author: Tamas Budavari, JHU
Date: April 2003, updated January 2005 (DR3)

sqlcl.py is a (very) simple Python program that can run SQL queries against SkyServer. Python runs on your favourite OS including the most exotic ones. The query goes through the same .aspx(x) page that you use in the web form or using wget.

March/04 Upgrades:

  • Comments supported within query
  • Header info is displayed if -v option is used
  • Space added to end of each line to fix an earlier bug.

For basic SQL help, go to the Intro to SQL page

Download sqlcl                   sqlcl.py [2 kB]       
View Python source file                   sqlcl.py.htm       

Command line examples/tutorial:

skysrv: budavari$ sqlcl.py -h
>> sqlcl << command line query tool by Tamas Budavari 
Usage: sqlcl [options] sqlfile(s)

Options:
        -s url     : URL with the ASP interface (default: pha)
        -f fmt     : set output format (html,xml,csv - default: csv)
        -q query   : specify query on the command line
        -l         : skip first line of output with column names
        -h         : show this message
        -v	   : display header information
        
skysrv: budavari$ sqlcl.py -q "select top 2 ra,dec from star"
ra,dec
238.60018,3.467897E-1
238.601051,-5.516095E-1

skysrv: budavari$ for i in 17 18; do \
echo "select top 2 ra,dec from star where r between "$i" and "$((i+1)) \
 > star$i.sql; done
skysrv: budavari$ sqlcl.py star??.sql
ra,dec
238.596559,-7.822902E-2
238.584209,-7.833417E-2
ra,dec
238.595337,2.787041E-1
238.594255,-1.397587E-1

skysrv: budavari$ sqlcl.py -l star??.sql
238.596559,-7.822902E-2
238.584209,-7.833417E-2
238.595337,2.787041E-1
238.594255,-1.397587E-1

Python examples/tutorial:

skysrv: budavari$ python2
Python 2.2 (#1, Apr 12 2002, 15:29:57) 
[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlcl
>>> print sqlcl.query("select top 2 ra, dec from galaxy").read()
ra,dec
238.594193,-5.39169E-1
238.588016,2.669783E-1

>>> lines = sqlcl.query("select top 2 ra, dec from galaxy").readlines()
>>> data = []
>>> for line in lines[1:]: data.append(map(float,line[:-1].split(',')))
... 
>>> print data
[[238.59419299999999, -0.53916900000000001], [238.58801600000001, 0.2669783]]
>>> print data[0]
[238.59419299999999, -0.53916900000000001]
>>> print data[0][0]
238.594193
>>> print type(data[0][0])

>>> 

This should be enough to get you started, let me know if you need more help!

Download sqlcl                   sqlcl.py [2 kB]       
View Python source file                   sqlcl.py.htm