TugQL

TugQL syntax cheat sheet

The clause order, projection forms, source qualifiers, parameters and comments used in TugQL text queries.

A complete read query

parameters (
  @MinInvoices integer default 2
)
from Invoice as i
where i.InvoiceId > 1
group by i.CustomerId
having COUNT(*) >= @MinInvoices
order by i.CustomerId asc
select i.CustomerId, COUNT(*) as InvoiceCount

Write FROM, optional WHERE, GROUP BY, HAVING, ORDER BY and LIMIT, then optional SELECT. The parameters block precedes the query. This example comes from the Go implementation's authoring reference; execution still depends on the connected database and adapter.

Projection and aliases

A compact projection separates items with commas. A multiline projection puts one item on each line, without commas. Use as for an output alias or source alias.

from Invoice as i
select (
  i.InvoiceId as ID
  i.CustomerId
)

Sources and databases

Use a dotted source such as sales.Invoice (a schema path) or a slash path such as spaces/{SpaceID}/ext/datatug/projects. A root databases block declares database aliases; alias::source selects a declared database. The dot and double colon have different meanings.

databases (
  sales
  geo
)
from sales::Invoice as i
join geo::Country as c
  on i.BillingCountry = c.Name
select i.InvoiceId, c.Name

A cross-database join requires an explicit on condition. The caller supplies authorized schemas for resolution and a database resolver for execution. The executing tool must check each source against its database access policy. Read the cross-database reference.

Comments and saved text

TugQL text accepts -- and // comments. YAML uses #. A quoted database target is required when it contains //, such as a URL. Read the comment conversion rules.

from Invoice as i -- billing records
where i.InvoiceId > 10
select i.InvoiceId

All documentation