<style>
code {
    background-color: #ffeeee;
    padding: 1px 3px;
    color: #901616;
}
</style>

<h2>Basic syntax</h2>
<p>
At this website it is possible to select galaxies in the RCSED catalog using simple boolean expressions query language which mimics syntax of <code>WHERE</code> clause in SQL language. The language consists of arbitrary number of <i>expressions</i> combined together using <code>AND</code> or <code>OR</code> clauses. <i>Expression</i> usually has the following structure (square brackets mean optional clauses):
</p>

<p>
<code>
parameter operator value [AND | OR [NOT] expression] [, …]
</code>
</p>

<p>
where <code>parameter</code> is the name of any galaxy property (i.e. column) present in the database or simple arithmetical operation between any number of properties (<code>*</code>, <code>/</code>, <code>-</code>, and <code>+</code> are supported). There is no unit specification so the actual query compares the data with user input value in the default database units. See the RCSED schema <a href="/docs/columns">documentation</a> for the list of available catalog columns.
</p>

<p>
Operator can be any comparison operator from SQL-like languages:
</p>

<ul>
<li><code>=</code> tests equality</li>
<li><code>!=</code> tests non-equality</li>
<li><code>&gt;</code> greater than (does not work for string parameters)</li>
<li><code>&lt;</code> less than (does not work for string parameters)</li>
<li><code>&gt;=</code> greater or equal than (does not work for string parameters)</li>
<li><code>&lt;=</code> less or equal than (does not work for string parameters)</li>
</ul>

<p>
Value in <i>expression</i> can be any string in double or single quotes, integer or float number in decimal notation with the point as a decimal separator. Value must correspond to parameter datatype, i.e. one can't compare string and float number. Use keyword <code>NOT</code> before the expression to negate it.
</p>

<p>
Slightly different syntax for expression is employed for testing substring inclusion in parameters of a string type:<br />

<code>
"substring" IN parameter_string
</code>
<br />

Another alternative tests for presence of desired substring(s) as a separate word(s) in <code>parameter_string</code>:<br />

<code>
{"substring1" [, "substring2" [, ...]]} IN parameter_string
</code>
<br />

which is often equivalent of the query <code>"substring1" IN parameter_string AND "substring2" IN parameter_string</code>, though not exactly.

Please also keep in mind that you have flexibility to change places of parameter and value in <i>expressions</i> and the overall language is case-insensitive.
</p>

<h2>Special functions</h2>

<ul>
<li><code>cone('object_name', 'search_radius')</code></li>
Make cone search in the catalog with specified radius around object. <code>object_name</code> is a quoted string with an object name to be resolved through the CDS Simbad service and <code>search_radius</code> is a quoted string in a format of value with units, e.g. <code>1.0deg</code>, <code>1arcmin</code>, <code>15arcsec</code>

<li><code>cone('ra', 'dec', 'search_radius')</code></li>
Cone search the catalog around known coordinates <code>ra</code> and <code>dec</code> with specified radius <code>search_radius</code>. <code>ra</code> and <code>dec</code> can be quoted colon-separated strings in sexagesimal notation, or unquoted float numbers. <code>search_radius</code> is same as in the cone search function above.

<li><code>object_name</code></li>
Unquoted object name without any other conditions is rewritten to <code>cone('object_name', '1arcmin')</code>
</ul>

<h2>Query related tables</h2>

<p>
By default query language operates on main <code>rcsed</code> table and transparently uses its column names, whereas there is a lot of additional information in related tables such as <code>rcsed_fibermags</code> or <code>rcsed_lines_gauss</code>. To be able to query them and address their columns as well we implemented transparent join on <code>objid</code> column and namespaced additional tables columns as follows:

<ul>
<li><code>rcsed_fibermags</code> (column name prefix: <code>fibermags_</code>)</li>
<li><code>galaxyzoo</code> (column name prefix: <code>galaxyzoo_</code>)</li>
<li><code>rcsed_lines_gauss</code> (column name prefix: <code>gauss_</code>)</li>
<li><code>rcsed_lines_nonpar</code> (column name prefix: <code>nonpar_</code>)</li>
<li><code>rcsed_lines_nonpar_reg</code> (column name prefix: <code>nonpar_reg_</code>)</li>
</ul>

So you one just needs to prepend table column name with corresponding table prefix, for example query
</p>

<p>
<code>
corrmag_g - corrmag_r > 0.75 AND galaxyzoo_spiral = 1
</code>
</p>

<p>
will return all galaxies with red <i>g-r</i> color, classified as spirals in Galaxy Zoo. For the full list of related table columns see the <a href="/docs/columns" target="_blank">RCSED columns page</a>.
</p>

<h2 id="examples">Example queries</h2>
<ul>
<li><code>M60</code> – select galaxies in 1 arcmin vicinity of M60 center</li>
<li><code>12:58:09.22 +28:42:30.9</code> or <code>12 58 09.22 28 42 30.9</code> or <code>194.5385 28.7086</code> – search 1 arcmin vicinity of sexagesimal or decimal coordinates</li>
<li><code>cone('NGC4889', '1deg') AND z &lt; 0.032 AND corrmag_u &lt; 18</code> – select galaxies from Coma cluster brighter than 18 mag in <i>SDSS u</i> band not further than 1 degree from its central galaxy NGC4889</li>
<li><code>objid IN {587722952230175138, 587722952230634398}</code> – select specific galaxies by their object IDs (useful for larger subsets)</li>
</ul>

<h2>SQL access</h2>
<p>
If you feel constrained with this simple query language, try more powerful SQL-like queries in the Astronomical Data Query Language <a href="http://rcsed-vo.sai.msu.ru/__system__/adql/query/form" target="_blank">interface</a> which serves as an open source SDSS CasJobs analog. 
</p>