SQL Expression Language

Used in @check, @default, and @initialize_as. This is not raw SQL. Immigrant has its own expression syntax that compiles to SQL.

Operators

Precedence Operator SQL equivalent

Highest

-x, +x, !x

-, +, NOT

*, /, %

*, /, %

+, -

+, -

<, >, <=, >=

same

~~

LIKE

==, !=

=, <>

===, !==

IS NOT DISTINCT FROM, IS DISTINCT FROM

&&

AND

Lowest

||

OR

Other expressions

table Example {
    a: sql"INTEGER"
        /// placeholder for current value
        @check(_ > 0)
        /// null literal
        @check(_ != null)
        /// boolean literal
        @check(_ == true)
        /// string literal
        @check(_ != 'forbidden')
        /// numeric literal
        @check(_ != 42)
        /// function call
        @check(char_length(_) > 0)
        /// cast
        @check(_ :: BIGINT > 0)
        /// conditional (CASE WHEN ... THEN ... ELSE ... END)
        @check(if _ > 10 then true else false)
    ;
};

/// field access on composites
struct example {
    a: sql"INTEGER";
    @check(_.a > 0);
};