This document describes the features of Hog.
Comments
// Hog comments start with //
-- You can also use SQL style comments with --
/* or C++ style multi line
blocks */Variables
// assign 12 to myVar
let myVar := 12 // must use ":=" because "=" is just equals in SQL/HogQL
myVar := 13
myVar := myVar + 1Comparisons
let myVar := 12
print(myVar = 12 or myVar < 10) // prints true
print(myVar < 12 and myVar > 12) // prints false
let string = 'mystring'
print(string ilike '%str%') // like, ilike, not like, not ilike workRegex
print('string' =~ 'i.g$') // true
print('string' !~ 'i.g$') // false
print('string' =~* 'I.G$') // true, case insensitive
print('string' !~* 'I.G$') // false, case insensitiveArrays
let myArray := [1,2,3]
print(myArray.1) // prints 2
print(myArray[1]) // prints 2Tuples
let myTuple := (1,2,3)
print(myTuple.1) // prints 2
print(myTuple[1]) // prints 2Objects
let myObject := {'key': 'value'} // must use single quotes !!
print(myTuple.key) // prints 'value'
print(myTuple['key']) // prints 'value'Strings
let str := 'string'
print(str || ' world') // prints 'string world', SQL concat
print(f'hello {str}') // prints 'hello string'
print(f'hello {f'{str} world'}') // prints 'hello string world'
print(empty(str) ? 'empty' : 'not empty') // prints 'not empty'Functions
// can only be defined at the top scope
fn addNumbers(num1, num2) {
let newNum := num1 + num2
return newNum
}
print(addNumbers(1, 2))Logic
let a := 3
if (a > 0) {
print('yes')
}
print(a > 0 ? 'yes' : 'no') // ternaryNulls
let a := null
print(a ?? 'is null') // prints 'is null'
print(a ? 'is null' : 'not null') // prints 'is null'
print(empty(a) ? 'is null' : 'not null') // prints 'is null'While loop
let i := 0
while(i < 3) {
print(i) // prints 0, 1, 2
i := i + 1
}For loop
while(let i := 0; i < 3; i := i + 1) {
print(i) // prints 0, 1, 2
}concat(...args)match(string, regex)toString(arg)toUUID(arg)toInt(arg)toFloat(arg)ifNull(value, alternative)length(stringOrArray)empty(arg)notEmpty(arg)tuple(...args)lower(str)upper(str)reverse(str)print(...args)jsonParse(str)jsonStringify(obj)base64Encode(str)base64Decode(str)tryBase64Decode(str)encodeURLComponent(str)decodeURLComponent(str)replaceOne(string, needle, replacement)replaceAll(string, needle, replacement)