Join Chinook and geo-ingitdb with TugQL
Walk through one TugQL read query that joins Chinook invoices to country aliases and population data in a Git-backed database.
The query
This is the same source shown on the homepage. It names the two data sources explicitly and projects country, total and population.
-- one query, two databases
databases (
chinook = 'https://cloud.openvaultdb.com/v1/databases/chinook'
geo = 'https://github.com/ingitdb/geo-ingitdb'
)
from chinook::Invoice as i
join geo::country_aliases as a
on i.BillingCountry = a.alias
join geo::population_wb as p
on a.country = p.country
group by i.BillingCountry, p.population
order by Total desc
select (
i.BillingCountry as Country
SUM(i.Total) as Total
p.population as Population
)
Open this exact query in DataTug. The link carries the text in the URL fragment. Execution depends on DataTug's current access to both data sources; this page does not claim a fixed result set.
Read it in four steps
databasesdeclareschinookandgeo. The target strings identify the two sources; connection credentials stay outside the query.from chinook::Invoicereads invoices.join geo::country_aliasesmatches the billing country to an alias, thenjoin geo::population_wbadds population by canonical country.group byprepares the aggregate.SUM(i.Total)computes the total for each group;order by Total descrequests a result order.selectnames the three returned columns. Projection is the final text clause in TugQL.
For a cross-database join, on is explicit because relationship metadata cannot be inferred across separate databases. The executing tool must check each source against that database's access policy.
What executes where
The cross-database reference defines aliases, qualified sources and failure modes. The executing tool binds aliases to databases. Each source is read from its own database; the federated engine performs joins and grouping across them. A backend does not receive this entire text as native SQL.
Inspect the geo-ingitdb source repository and the Go implementation for the current execution contract.