Examples

Number of TGAS stars with parallax / parallax_error > 10

Count the number of stars in the TGAS catalog with parallax / parallax_error > 10;

SELECT COUNT(*)
FROM gdr1.tgas_source
WHERE parallax / parallax_error > 10;

Histogram of TGAS G magnitudes

Compute the histogram of TGAS G magnitudes.

SELECT gmag * 0.1 AS gmag_bin, COUNT(gmag) AS number
FROM
(
    SELECT FLOOR(phot_g_mean_mag * 10) AS gmag
    FROM gdr1.tgas_source
) AS gmag_tab
GROUP BY gmag;

M4 globular cluster with geometric distances using ADQL

None

SELECT gaia.source_id, gaia.ra, gaia.dec, gd.r_est
FROM gdr2.gaia_source gaia, gdr2_contrib.geometric_distance gd
WHERE 1 = CONTAINS(POINT('ICRS', gaia.ra, gaia.dec), 
                   CIRCLE('ICRS',245.8962, -26.5222, 0.5))
AND gaia.phot_g_mean_mag < 15
AND gd.r_est > 1500 AND gd.r_est < 2300
AND gaia.source_id = gd.source_id

M4 globular cluster using PostgreSQL

None

-- Run with PostgreSQL
-- Input of function spoint() must be in radians!

SELECT ra, dec, phot_g_mean_mag AS gmag
FROM gdr1.gaia_source
WHERE pos @ scircle(spoint(RADIANS(245.8962), RADIANS(-26.5222)), RADIANS(0.5))
AND phot_g_mean_mag < 15

Gaia data with 2MASS photometry

Combine Gaia information with 2MASS J, H and Ks photometric measurements.

-- Gaia + 2MASS photometry

SELECT TOP 10 gaia.ra, gaia.dec,
       gaia.phot_g_mean_mag, gaia.phot_bp_mean_mag, gaia.phot_rp_mean_mag,
       tmass.j_m, tmass.h_m, tmass.k_m, tmass.ph_qual
FROM gdr2.gaia_source AS gaia,
	 gdr2.tmass_best_neighbour AS xm,
     catalogs.tmass AS tmass
WHERE gaia.source_id = xm.source_id
AND xm.tmass_oid = tmass.tmass_oid;

Orbital elements of Solar System Objects

Select orbital elements of all available SSOs.

SELECT osc_epoch, orb_m, omega, node_omega, inclination, eccentricity, a
FROM gdr2.aux_sso_orbits;

Epoch photometry data with more than 100 measurements

Select first 10 light curves that have more than 100 points. This query operates on data that is packed into arrays and must therefore be run with PostgreSQL.

-- Run with PostgreSQL

SELECT gaia.ra, gaia.dec,
	   ep.source_id, ep.g_transit_time, ep.g_transit_flux
FROM gdr2.gaia_source AS gaia, gdr2.epoch_photometry AS ep
WHERE array_length(ep.g_transit_time, 1) > 100
AND ep.source_id = gaia.source_id
LIMIT 10;

Parameters of bright stars with radial velocity measurements

None

-- Replace COUNT(*) with requested columns

SELECT COUNT(*)
FROM gdr2.gaia_source
WHERE phot_g_mean_mag < 12
AND radial_velocity IS NOT NULL;

All-sky radial velocity map

Select stars with radial velocity measurements, use the source_id to compute the HEALPix index and uniformly limit the number of stars using random_index.

-- Compute HEALPix value from source_id

SELECT FLOOR(source_id / (POW(2, 35) * POW(4, 6))) AS hpix, radial_velocity AS rv
FROM gdr2.gaia_source
WHERE random_index < 10000000
AND radial_velocity IS NOT NULL;

47Tuc Hertzsprung–Russell diagram

Hertzsprung–Russell diagram of the famous globular cluster 47Tuc.

SELECT bp_rp, phot_g_mean_mag AS gp
FROM gdr2.gaia_source
WHERE 1 = CONTAINS(POINT('ICRS', ra, dec),
                   CIRCLE('ICRS', 6.0223292, -72.0814444, 0.2))
AND phot_g_mean_flux_over_error > 50
AND phot_rp_mean_flux_over_error > 20
AND phot_bp_mean_flux_over_error > 20
AND phot_bp_rp_excess_factor < 1.3 + 0.06 * POW(bp_rp, 2)
AND phot_bp_rp_excess_factor > 1.0 + 0.015 * POW(bp_rp, 2)
AND visibility_periods_used > 8
AND astrometric_chi2_al / (astrometric_n_good_obs_al - 5) <
    1.44 * greatest(1, exp(-0.4 * (phot_g_mean_mag - 19.5)));

Easter egg

This examples shows how to make complex spatial selections using polygons.

-- Run with PostgreSQL

SELECT ra, dec
FROM gdr2.gaia_source
WHERE pos @ sbox(spoint(0.0, RADIANS(0.5)), spoint(RADIANS(4.0), RADIANS(7.0)))
AND pos !@ spoly '{(0.610000d,1.040000d), (0.690000d,1.040000d), (1.050000d,1.990000d),
(1.140000d,2.000000d), (1.480000d,1.040000d), (1.540000d,1.040000d), (1.540000d,0.970000d),
(1.200000d,0.970000d), (1.200000d,1.040000d), (1.300000d,1.040000d), (1.050000d,1.740000d),
(0.910000d,1.380000d), (1.170000d,1.370000d), (1.200000d,1.280000d), (0.880000d,1.280000d),
(0.790000d,1.040000d), (0.890000d,1.040000d), (0.900000d,0.970000d), (0.600000d,0.970000d)}'
AND pos !@ spoly '{(1.690000d,0.970000d), (1.690000d,1.040000d), (1.810000d,1.040000d),
(1.810000d,1.930000d), (1.690000d,1.940000d), (1.690000d,2.010000d), (2.120000d,2.010000d),
(2.120000d,1.940000d), (2.000000d,1.940000d), (2.000000d,1.050000d), (2.120000d,1.040000d),
(2.110000d,0.970000d)}'
AND pos !@ spoly '{(2.310000d,0.970000d), (2.310000d,1.040000d), (2.420000d,1.050000d),
(2.420000d,1.940000d), (2.310000d,1.940000d), (2.310000d,2.010000d), (2.810000d,2.010000d),
(2.870000d,2.000000d), (2.940000d,1.960000d), (2.990000d,1.920000d), (3.020000d,1.880000d),
(3.060000d,1.800000d), (3.070000d,1.730000d), (3.060000d,1.630000d), (3.020000d,1.540000d),
(2.960000d,1.480000d), (2.890000d,1.430000d), (2.810000d,1.400000d), (2.720000d,1.390000d),
(2.670000d,1.400000d), (2.670000d,1.480000d), (2.750000d,1.480000d), (2.820000d,1.530000d),
(2.860000d,1.600000d), (2.870000d,1.750000d), (2.840000d,1.820000d), (2.800000d,1.890000d),
(2.750000d,1.920000d), (2.610000d,1.910000d), (2.610000d,1.040000d), (2.740000d,1.040000d),
(2.740000d,0.970000d)}'
AND pos !@ spoly '{(0.290000d,2.620000d), (0.700000d,2.650000d), (1.060000d,2.670000d),
(1.450000d,2.690000d), (2.060000d,2.690000d), (2.530000d,2.680000d), (3.020000d,2.660000d),
(3.300000d,2.630000d), (3.650000d,2.600000d), (3.840000d,2.580000d), (3.810000d,2.510000d),
(3.340000d,2.550000d), (2.900000d,2.560000d), (2.500000d,2.580000d), (2.000000d,2.590000d),
(1.500000d,2.580000d), (1.040000d,2.570000d), (0.670000d,2.560000d), (0.160000d,2.520000d),
(-0.020000d,2.500000d)}'
AND pos !@ spoly '{(0.280000d,6.560000d), (0.420000d,6.580000d),
(0.630000d,6.590000d), (1.000000d,6.590000d), (1.330000d,6.560000d), (1.550000d,6.520000d),
(1.760000d,6.480000d), (2.050000d,6.410000d), (2.290000d,6.330000d), (2.560000d,6.230000d),
(2.860000d,6.100000d), (3.090000d,5.970000d), (3.310000d,5.830000d), (3.550000d,5.660000d),
(3.710000d,5.540000d), (3.830000d,5.430000d), (3.770000d,5.380000d), (3.630000d,5.500000d),
(3.470000d,5.610000d), (3.280000d,5.730000d), (3.050000d,5.870000d), (2.880000d,5.970000d),
(2.640000d,6.080000d), (2.370000d,6.190000d), (2.130000d,6.280000d), (1.840000d,6.360000d),
(1.570000d,6.420000d), (1.260000d,6.470000d), (0.980000d,6.490000d), (0.760000d,6.490000d),
(0.320000d,6.490000d)}'
AND pos !@ spoly '{(1.050000d,3.320000d), (1.100000d,3.780000d), (1.170000d,4.170000d),
(1.270000d,4.560000d), (1.400000d,4.930000d), (1.510000d,5.230000d), (1.590000d,5.410000d),
(1.720000d,5.650000d), (1.840000d,5.880000d), (1.960000d,6.060000d), (2.410000d,5.890000d),
(2.670000d,5.770000d), (2.950000d,5.630000d), (2.880000d,5.330000d), (2.810000d,4.980000d),
(2.750000d,4.690000d), (2.700000d,4.300000d), (2.670000d,3.960000d), (2.630000d,3.420000d),
(2.630000d,2.930000d), (2.410000d,2.950000d), (1.900000d,2.970000d), (1.060000d,2.940000d)}'
OR (
  pos @ spoly '{(1.580000d,3.250000d), (1.610000d,3.370000d), (1.650000d,3.250000d),
  (1.760000d,3.220000d), (1.640000d,3.190000d), (1.610000d,3.070000d), (1.580000d,3.190000d),
  (1.470000d,3.220000d)}'
  OR pos @ spoly '{(1.850000d,3.460000d), (1.890000d,3.580000d),
  (1.940000d,3.460000d), (2.070000d,3.410000d), (1.950000d,3.350000d), (1.890000d,3.220000d),
  (1.850000d,3.350000d), (1.730000d,3.390000d)}'
  OR pos @ spoly '{(2.290000d,3.850000d), (2.320000d,3.980000d), (2.350000d,3.870000d),
  (2.470000d,3.830000d), (2.340000d,3.790000d), (2.320000d,3.680000d), (2.280000d,3.790000d),
  (2.190000d,3.820000d)}'
  OR pos @ spoly '{(1.790000d,4.540000d), (1.840000d,4.740000d),
  (1.900000d,4.540000d), (2.060000d,4.490000d), (1.900000d,4.420000d), (1.840000d,4.260000d),
  (1.790000d,4.420000d), (1.630000d,4.480000d)}'
  OR pos @ spoly '{(2.030000d,4.590000d), (2.070000d,4.710000d), (2.110000d,4.590000d),
  (2.220000d,4.560000d), (2.120000d,4.530000d), (2.070000d,4.410000d), (2.030000d,4.530000d),
  (1.920000d,4.560000d)}'
  OR pos @ spoly '{(2.480000d,4.540000d), (2.510000d,4.640000d),
  (2.560000d,4.530000d), (2.650000d,4.510000d), (2.550000d,4.470000d), (2.520000d,4.350000d),
  (2.480000d,4.460000d), (2.370000d,4.500000d)}'
  OR pos @ spoly '{(1.820000d,4.780000d),
  (1.870000d,4.840000d), (1.900000d,4.780000d), (1.960000d,4.740000d), (1.910000d,4.710000d),
  (1.870000d,4.650000d), (1.820000d,4.710000d), (1.780000d,4.730000d)}'
  OR pos @ spoly '{(1.940000d,4.840000d), (1.960000d,4.890000d), (2.000000d,4.830000d),
  (2.030000d,4.820000d), (2.000000d,4.790000d), (1.970000d,4.740000d), (1.940000d,4.790000d),
  (1.900000d,4.810000d)}'
  OR pos @ spoly '{(2.250000d,4.970000d), (2.290000d,5.090000d), (2.340000d,4.980000d),
  (2.440000d,4.940000d), (2.330000d,4.900000d), (2.300000d,4.800000d), (2.270000d,4.900000d),
  (2.160000d,4.930000d)}'
  OR pos @ spoly '{(2.340000d,5.660000d), (2.360000d,5.710000d),
  (2.400000d,5.660000d), (2.470000d,5.640000d), (2.420000d,5.590000d), (2.370000d,5.520000d),
  (2.330000d,5.590000d), (2.270000d,5.620000d)}'
  OR pos @ spoly '{(1.720000d,5.180000d),
  (1.770000d,5.210000d), (1.830000d,5.210000d), (1.870000d,5.180000d), (1.880000d,5.120000d),
  (1.860000d,5.060000d), (1.830000d,5.040000d), (1.780000d,5.040000d), (1.720000d,5.060000d),
  (1.710000d,5.090000d)}'
  OR pos @ spoly '{(2.090000d,4.760000d), (2.130000d,4.870000d), (2.160000d,4.770000d),
  (2.270000d,4.740000d), (2.170000d,4.690000d), (2.130000d,4.590000d), (2.100000d,4.690000d),
  (1.990000d,4.720000d)}'
)

Compare coordinates between Gaia DR1 and DR2

None

SELECT TOP 1000 dr1.ra as dr1_ra, dr1.dec as dr1_dec, dr2.ra as dr2_ra, dr2.dec as dr2_dec
FROM gdr1.gaia_source AS dr1, gdr2.gaia_source AS dr2, gdr2.dr1_neighbourhood AS xm
WHERE dr1.source_id = xm.dr1_source_id
AND dr2.source_id = xm.dr2_source_id;