ADQL and PostgreSQL

The Gaia@AIP services run with PostgresQL database which you can access through the Query interface. To retrieve data from the tables, the tables are queried. An SQL statement is used to do this. For each query you can choose which SQL language to use. The Django Daiquiri framework released with the Gaia DR2, unpdated with Gaia DR3, supports ADQL and PostgreSQL.

The ADQL or Astronomical Data Query Language was designed specifically to be used in astronomy and comes with statements that facilitate cone-search queries and other positional selections. It is developed by the Virtual Observatory (VO) to represent astronomical queries send to IVOA services.

All ADQL queries that are submitted for the execution are translated to PostgreSQL dialect before they are passed to the database server. Users can also choose to write their queries in the PostgreSQL dialect directly. In some cases this is more powerful, since the ADQL does not support all features that are available in PostgreSQL, namely working with array structures.

As an example let us write an ADQL query that selects stars around the M4 globular cluster from the Gaia DR1 main table:

SELECT ra, dec
FROM gdr1.gaia_source
WHERE 1 = CONTAINS(POINT('ICRS', ra, dec),
                   CIRCLE('ICRS',4.2917,-0.4629, 0.008))

The cone selection is done using the CONTAINS statement. Alternatively, we can rewrite the same query using the PostgreSQL dialect in the following way:

SELECT ra, dec
FROM gdr1.gaia_source
WHERE pos @ scircle(spoint(RADIANS(4.2917),RADIANS(-0.4629)), RADIANS(0.008))

Here we use the PgSphere functions 'scircle' and 'spoint' to define the region. We connect the column containing the positional information (right ascension and declination) 'pos' to the cone selection with the @ operator. And the functions require coordinates in RADIANS, not degrees. To learn more about the available PgSphere functions and capabilities please refer to the documentation here

The SQL queries must be either in ADQL or PostgreSQL depending on the task. For example, ADQL will provide some specific geometry functions, which other SQL languanges do not have. On the other hand, some common SQL syntax will not work with ADQL and you will have to switch to PostgreSQL.

Please take a look at the Query examples to find examples of queries in both dialects for the Gaia dataset.

ADQL

Additional information on ADQL you can find here:

For the complete documentation and specification of ADQL please look up IVOA ADQL documentation.

PostgreSQL

PostgreSQL uses SQL dialect to query the data in the database.

Search