| Ocalt Query Language
Pricing Dashboard ocalt.com v1.0

EMIT

EMIT is the primary output verb in OQL. It sets the query result and, in most contexts, terminates the current chain. Understanding exactly when it terminates and when it combines is essential.

Basic usage

EMIT returns any value as the query result. It accepts variables, literals, expressions, and object field access.

EMIT "Hello, World!"
Try it ›
WRITE "Hello" INTO "/root/greet.txt" AFTER READ "/root/greet.txt" SET ?content AFTER EMIT ?content
Try it ›

EMIT terminates the chain

In a sequential chain, only the last EMIT in the chain is returned. Earlier EMIT calls are evaluated (and their side effects run) but their values are replaced by later ones.

EMIT "first" AFTER EMIT "second" AFTER EMIT "third"

Result: "third". The last EMIT wins.

Try it ›

EMIT with AND — parallel output

When EMIT appears alongside AND EMIT, all values are collected into an array. The left-hand EMIT value is prepended to the parallel results.

EMIT "alpha" AND EMIT "beta" AND EMIT "gamma"

Result: ["alpha", "beta", "gamma"]

Try it ›

Variables resolved before the parallel split are preserved:

FETCH "https://httpbin.org/uuid" SET ?r AFTER EMIT ?r(uuid) AND EMIT "done"

Result: ["<uuid>", "done"]

Try it ›

EMIT inside HTML blocks

Inside an HTML block, EMIT does not return a query result — it appends to the HTML buffer of that block. The block itself returns the assembled HTML string when it closes.

HTML "div" CLASS "card" OPEN NEST EMIT "Hello from inside a div" CLOSE NEST SET ?card AFTER EMIT ?card
Try it ›

EMIT inside EMAIL blocks

Inside an EMAIL block, EMIT appends to the email body buffer. It does not produce a query result. The EMAIL verb sends on CLOSE NEST.

EMAIL TO "user@example.com" WITH "Hello" OPEN NEST EMIT "This is the body." CLOSE NEST

EMIT inside IF / FOREACH / WHILE

EMIT inside a control flow block returns its value to the block's result, which then propagates as the block's output. The block result then participates in the outer chain normally.

CAST "5" AS "number" SET ?n AFTER IF ?n IS GREATER THAN 3 OPEN NEST EMIT "big" CLOSE NEST OR OPEN NEST EMIT "small" CLOSE NEST SET ?size AFTER EMIT ?size
Try it ›

EMIT on a multivariable

Emitting a multivariable (AND branches sharing the same name) returns one value at random from the active branches. Use COLLAPSE first if you want all values as an array.

UPPER "alpha" SET ?r AND UPPER "beta" SET ?r AND UPPER "gamma" SET ?r AFTER EMIT ?r

Result: one of "ALPHA", "BETA", or "GAMMA" — chosen at random.

Try it ›

EMIT GEOIP — client location

EMIT has a special form for returning geolocation data about the client IP.

VerbReturns
EMIT GEOIP ADDRESSClient IP address string
EMIT GEOIP CITYCity name string
EMIT GEOIP COUNTRYCountry name string
EMIT GEOIP REGIONState/province name string
EMIT GEOIP LATLatitude number
EMIT GEOIP LONLongitude number
EMIT GEOIP ALL{ip, city, country, region, lat, lon} object for client IP
EMIT GEOIP "1.2.3.4"{ip, city, country, region, lat, lon} object for a specific IP

When EMIT does NOT work as expected

SituationBehaviourFix
Multiple sequential EMITsOnly the last EMIT value is returnedBuild an array and EMIT it once, or use AND EMIT for parallel collection
EMIT inside HTML blockAppends to HTML buffer, not query resultCapture the block result with SET and EMIT it after CLOSE NEST
EMIT inside EMAIL blockAppends to email body buffer onlyEMIT after CLOSE NEST if you need a result
EMIT ?multivariableReturns one random branch valueCOLLAPSE ?multivariable SET ?arr AFTER EMIT ?arr if you need all values
EMIT ?undefinedReturns nullEnsure the variable is SET before EMIT
EMIT before AFTER chainValue discarded by next AFTER step resultEMIT only at the end of the chain, or use AND EMIT to merge with parallel values

EMIT vs RETURN

RETURN exits the entire query immediately with the given value — including breaking out of nested blocks and loops. EMIT does the same in a flat chain but participates in parallel collection with AND. Use RETURN when you need to exit from inside a FOREACH or WHILE; use EMIT for normal output.

Quick reference

PatternResult
EMIT "x"String "x"
EMIT ?varValue of ?var (null if unset)
EMIT ?obj(key)Field key from object ?obj
EMIT "x" AND EMIT "y"Array ["x","y"]
EMIT ?v AND EMIT "y"Array [value_of_v, "y"]
EMIT "x" AFTER EMIT "y"String "y" — last wins
EMIT GEOIP CITYClient city string