[ English | Japanese ]
DARTS/Astro Query System User Guide
How to use "SQL Search" and "ADQL Search"
In SQL Search and ADQL Search, you can search database directly by entering SQL queries to specify search conditions. You can create your own search conditions and/or sort the results in any orders.
- Basic syntax of SQL / ADQL
- Examples and explanations of SQL / ADQL
- Formats of the search results
- Showing the used SQL query
- Downloading the data
Basic syntax of SQL / ADQL
In Darts/Astro Query System, we adopt PostgreSQL for the RDBMS, as well as PgSphere as an extension. You can use any functions defined in these systems.
Standard of ADQL, which is an extension of the standard SQL92, is defined in IVOA Recommendation. In ADQL search, the input ADQL statements are converted into the SQL statements which are interpreted with PostgreSQL and PgSphere.
Here is the basic syntax of SQL and ADQL, where "{value1|value2}" means either of "value1" or "value2", and "[phrase]" means that the "phrase" may be omitted:
SELECT {*|column1,column2 column3,...}
FROM table_name
[ WHERE conditions ]
[ ORDER BY column1, column4, ... ]
[ LIMIT {number|ALL} [ OFFSET number ]
;
SELECT
TOP number
{*|column1,column2,column3,...}
FROM table_name
[ WHERE conditions ]
[ ORDER BY column1, column4, ... ]
;
SELECT
clause-
From the tables specified
with
FROM
clause, the database items used to search are specified withSELECT
(comma-separated). This is a required item. To specify all the items in the tables, use "*
". Please refer to the following for database items in all the tables. FROM
clause- Specify tables to search within. This is a required item.
WHERE
clause-
Specify search conditions. You can combine two or more search conditions using
AND
orOR
, whereAND
has a higher priority thanOR
. If you want to give a higher priority toOR
, use parentheses,( )
. ORDER BY
clause-
Specify database items based on which the search results are ordered. The output is displayed in the ascending order
if
ASC
is put after the database item, or descending order ifDESC
is put. Default is the ascending order whenASC
is omitted. If two or more database items separated by ",
" are specified, the second (third, fourth, and so on) database item is used to judge the order when the first (second, third, and so on) item has the same order. LIMIT
/TOP
clause-
LIMIT
/TOP
specifies the maximum number of search results, as well as the number to skip. While this is an optional item, we would recommend to specify a reasonable upper-limit, because response of the browser can be very slow when a large amount of the data are accidentally hit.These specifications are not clearly established in the Standard SQL, and so that the implementation varies in different database systems. In PostgreSQL,
LIMIT
is used, whileTOP
is adopted in ADQL. Accordingly, we useLIMIT
in SQL Search andTOP
in ADQL Search.The clause in SQL Search is as follows;
LIMIT {number|ALL} [ OFFSET {number} ]
OFFSET
specifies the number of lines to skip, where "OFFSET 0
" is identical to omittingOFFSET
. WhenOFFSET
is omitted, the number specified withLIMIT
is returned from the beginning. If bothOFFSET
andLIMIT
are specified, the first number of lines specified withOFFSET
are skipped, and output the results up to the number specified byLIMIT
.The clause in ADQL Search is as follows;
TOP number
- Ending character "
;
" -
Ending character "
;
" tells the end of an SQL statement. In DARTS/Astro Query System, the ending character may be omitted, but you may not specify two or more SQL statements separated by ";
". Please input a single SQL statement at a time.
Also, please refer to SQL tutorial and SQL general reference in DARTS/AKARI CAS page.
Examples and explanations of SQL / ADQL
In SQL Search and ADQL Search, we provide examples of typical query statements in SQL and ADQL. Clicking each of the "Call example", an exemplary SQL statement is put into the "SQL Query" or "ADQL Query" text box, and explanation of the statement is shown. You can edit the statement in the text box.
Search types | Explanation and example |
---|---|
Ranges Search |
You can use the following operators to compare values:
|
And, Or |
When you combine various conditions,
you can use AND or OR :
AND has a higher priority than OR ,
if you want to give a higher priority to OR ,
use parentheses, () .
|
Multiple match |
When searching the data matching one of various values or not-matching any of the values,
IN clause is convenient:
|
Pattern match |
For pattern matching, you may use LIKE operator:
If you want to treat '%' or '_' as a normal letter, please put "\" before the character, e.g. '10\%', 'STAR\_A'. |
Radial Search |
In radial search, it is convenient to use functions of PgSphere to define geometrical shape or region on the celestial sphere:
There are similar geometrical functions in ADQL Search:
|
Multiple Radial Search |
You can combine multiple radial search conditions using OR or
AND operators.
|
Rectangular Search |
You may carry out rectangular search using operators,
Equivalent expressions are written by using
BETWEEN syntax, please be careful if the boundaries are inclusive or not.
To search the piled up region specifying rectangle region of which region such as observation fields, it is convenient to use function of PgSphere, like Radial Search. Please refer to Radial Search in above this page. |
Formats of the search results
You can choose either html or CSV for the output format of the search results. Please specify from the "Format" pull-down menu.
Showing the SQL statement used
If you click "Show the used SQL", the SQL statement used in the search is displayed as a pop-up. This SQL sentence may be copied into the "SQL query" text box of SQL Search.
Downloading the data
If you click "Download Wget script", you can obtain a Wget script to download the data your selected.