Configurable QueryTablesAPI to call directly postgresql using cartodb-psql
or to keep using a request to the SQL API