The SELECT-FROM-WHERE is the basic building block of an SXQL query. The syntax is
SELECT selection_string FROM from_item WHERE predicate_string
The selection_string is one of the following:
The from_item is either
The predicate_string is the actual query specification for the class you specified in the from_item.
These operations can be used to whatever level using simple parentheses around the SELECT blocks. Example sketch:
(SELECT block) UNION ( SELECT block INTERSECT SELECT block )
Predicates are the conditions that you specify to select the subset of the data you are interested in. For example: Find all objects with i < 22 translates just to i < 22 in the WHERE clause. A more prominent example would be the quasar-selection query (from Fan et. al.)
(i < 19) && (u-g > 2 || u>22) && (g-r > 1.0) && (r-i < 0.2 + 0.42*(g-r - 1.0) || (g-r > 2.3)) && (i-z < 0.25)of course this is where all the effort goes to get something meaningful out of the data.
The predicate is composed of arithmetic and logical operators and a few SQL keywords. See the Operator Table below for details.
J2000 : RA() DEC() GALACTIC : GL() GB() SUPERGALACTIC : SGL() SGB() ECLIPTIC : ECL() ECB() SURVEY : LAMBDA() ETA()These macros have to be all written in uppercase, and with the two parenthesis. They work in any class that has an association with a tag class. But we recommend using them in the tag classes only.
To specify a cut, simply use the standard greater than and less than operators. To specify a range cut, use the SQL 'BETWEEN' keyword. Examples:
RA() > 45 DEC() BETWEEN 20 AND 25All declination coordinates have periodic ranges, so for example RA() < 365 will translate into RA() < 5. RA coordinates are restricted to be between -90,+90 degrees.
SELECT extractItems FROM ( SELECT * FROM className WHERE predicate1 ) WHERE predicate2Nested SELECT statements can be of two types. If we have a * (star) following the SELECT keyword (like in the example above). In that case, both the internal and external predicates (predicate 1 and 2 in the example above) are operating on the same class given by className.
The other nested SELECT type has an association name of the SELECT block's class (given by the FROM statement) instead of the * like
SELECT extractItems FROM (SELECT assocName FROM className WHERE predicate1) WHERE predicate2In this case, predicate1 is a set of constraints on the data members of the class given by className but predicate2 is operating on data members of the class that assocName refers to. Also, the extractItems refer to members of the EXTERNAL class, i.e. the same as predicate2.
Example: a way to get all stars that have been observed with sub-arcsecond seeing is
SELECT modelCounts FROM ( SELECT obj FROM field WHERE psfWidth[2] < 1 ) WHERE objType == AR_OBJECT_TYPE_STAR
Nested select queries are very well suited to speed up your query. Querying on fields and segments is very fast since there is only very few of them. If you select only a few fields or segments, it is usually much faster to use a nested select to get at the objects contained in them.
SXQL Keywords |
|
SELECT |
Begin select block |
FROM |
Specify class or nested select |
WHERE |
End select block, followed by predicate |
UNION |
Logical OR two select blocks |
INTERSECT |
Logical AND two select blocks |
DIFFERENCE |
Logical AND NOT two select blocks |
Coordinate Specifiers | |
J2000 |
Standard ra/dec coordinate system - use macros RA() DEC() |
GALACTIC |
Galactic coordinate system - use macros GL() GB() |
SUPERGALACTIC |
Supergalactic coordinate system - use macros SGL() SGB() |
SURVEY |
Survey coordinate system - use macros LAMBDA() ETA() |
ECLIPTIC |
Ecliptic coordinate system - use macros ECL() ECB() |
SXQL language keywords and macros | |
x BETWEEN a AND b |
Translates to
|
STR(expression,n,d) |
Only in the extractor specification: Format output of expression. n specifies the width and d the number of decimal places. |
COUNTASSOC(association) |
Only in the extractor specification: Return the number of associations |
EXIST(association) |
TRUE if an association from an object to another one exists. |
EXIST(association,n) |
TRUE if at least n associations from an object to another one exist. |
OID( (run,camcol,rerun,field,objID), (run,camcol,rerun,field,objID), ...) |
Macro selecting objects given by their SDSS id, which is run number, camera column, rerun, field and object id. You can specify between 1 and 10000 ids in a list. Currently this works only on the sxPhotoObj class (i.e. full photometric catalog objects only). |
PROX(coordspec, ra, dec, diameter) |
Macro returning objects within the area centered around the given coordinate with diameter specified by 'diameter'. Diameter has to be specified in arcminutes, not greater than 10. Coordspec can be any of the keywords given above. |
POLY(coordspec, ra_1, dec_1, ..., ra_N, dec_N) |
Macro returning objects within the polygonal area given by the N coordinate pairs in the given coordinate system. |
SXQL Math Functions | |
SIN(expression) |
Calculate sine function of expression. Expression can be any mathematical expression. |
COS(expression) |
Calculate cosine function of expression. |
SQRT(expression) |
Calculate square root of expression. |
LN(expression) |
Calculate natural logarithm of expression. |
LOG(expression) |
Calculate 10-based logarithm of expression. |
EXP(expression) |
Calculate natural exponentiation of expression. |
Arithmetic Operators | |
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
Logical Operators | |
&& or AND |
Logical AND |
|| or OR |
Logical OR |
! or NOT |
Logical NOT |
Number Comparison | |
= or == |
Equals |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal |
<= |
Less than or equal |
!= | Not equal |
Bitwise Operators | |
& |
Bitwise AND |
^ |
Bitwise XOR |
| |
Bitwise OR |
Dereferencing | |
. or -> | Follows association links |