The library already includes two default implementations which lets to translate ADQL into an SQL adapted to Postgres: PostgreSQLTranslator and PgSphereTranslator. Since there are always slight differences between the SQL of each DataBase Manager System (DBMS), you may have to write an implementation of ADQLTranslator (or an extension of PostgreSQLTranslator) adapted to your DBMS.
PostgreSQLTranslator is able
to translate any SQL-like part of an ADQL query into SQL. However, the geometrical functions
can not be translated for only Postgres...
Indeed, Postgres has no default way to manage geographical information. For that a plugin
like PgSphere and Q3C is required. In its current version,
the library includes only the translator for PgSphere. Thus, if you want to translate
fully (geometrical functions included) an ADQL query, you have to use
it is the only one to be able to properly translate functions like
Considering the following ADQL parsing:
ADQLParser parser = new ADQLParser(); ADQLQuery query = parser.parse("SELECT * FROM data WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', 13, 2, 10)) = 1");
ADQLTranslator translator = new PostgreSQLTranslator(); System.out.println("SQL (for Postgres alone):\n" + translator.translate(query));
ADQLTranslator translator = new PgSphereTranslator(); System.out.println("SQL (for Postgres + PgSphere):\n" + translator.translate(query));
Here are their respective output:
SQL (for Postgres alone): SELECT FROM data WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', 13, 2, 10)) = 1
SQL (for Postgres + PgSphere): SELECT FROM data WHERE (spoint(radians(ra),radians(dec)) @ scircle(spoint(radians(13),radians(2)),radians(10))) = '1'