Relational operators, also called logical operators and binary comparison operators, are used to verify the truth or falsity of certain conditional relationships. The expressions that contain them are called relational expressions. They accept various types of arguments, and the result is always of the true/false type; in other words, they produce a boolean result.

1 Introduction

All relational operators are binary operators, that is, they use two operands.

If the proposition is true, the result is true (a non-zero value). If it is false, a false (zero) result is returned. Relational operators are often used with conditional operators to formulate more complex expressions.

Relational operators
Operator Java Equivalent Class Description Applicable to
<eq> == BINARY Equality number | date | timestamp | string
<ne> != BINARY Inequality number | date | timestamp
<lt> < BINARY Less than number | date | timestamp
<gt> > BINARY Greater than number | date | timestamp
<le> <= BINARY Less than or equal to number | date | timestamp
<ge> >= BINARY Greater than or equal to number | date | timestamp

The result of a relational operation is always true or false. The decision table for the application of relational operators is shown below. Relationships not included in the table are not supported.

Application and Results of Binary Relational Operators
Type 1 Type 2 Result Operator Notes
null null true eq The equality operation returns a result of 'true' if the two arguments are null.
null any false eq The equality operation returns a result of 'false' if only one argument is null.
null any false lt | gt | le | ge Except for the eq function, other operations return a result of 'false' when one of the two arguments is null.
string any true | false ne | lt | gt | le | ge Functions return results of 'true' or 'false' depending on the relationship and if, lexicographically, the arguments are equal or one is greater than the other.
short short true | false ne | lt | gt | le | ge The functions return true or false depending on the relationship used and if arithmetically the arguments are equal or one is greater than the other.
number number true | false ne | lt | gt | le | ge Functions return results of 'true' or 'false' depending on the relationship and if, arithmetically via BigDecimal, the arguments are equal or one is greater than the other.
number number true | false ne | lt | gt | le | ge Functions return results of 'true' or 'false' depending on the relationship and if, arithmetically, the arguments are equal or one is greater than the other.
timestamp timestamp true | false ne | lt | gt | le | ge Functions return results of 'true' or 'false' depending on the relationship and if, temporally (via millisecond of date or timestamp), the arguments are equal or one is greater than the other.

2 <eq> function

This function determines if two values are equal. If they are, the function will return true. Otherwise, it returns false.

<eq>
    <value_1> !
    <value_2> !
</eq>
Example
Copy
<xsql-script name='sample'>
    <body>
        <set name='value_1'>10</set>
        <set name='value_2'>20</set>
        <!-- Sample 0 (false) -->
        <println><expr><eq><valor_1 /><valor_2 /></eq></expr></println>

         <set name='value_2'>10</set>
         <!-- Sample 1 (true) -->
         <println><expr><eq><valor_1 /><valor_2 /></eq></expr></println>

    </body>
</xsql-script>

3 <ne> function

This function determines if two values are not equal. If the values are different, the function will return true. Otherwise, it returns false.

<ne>
    <value_1> !
    <value_2> !
</ne>
Example
Copy
<xsql-script name='sample'>
    <body>
        <set name='value_1'>10</set>
        <set name='value_2'>20</set>
        <!-- Sample 0 (true) -->
        <println>
            <expr>
                <ne>
                    <value_1 />
                    <value_2 />
                </ne>
            </expr>
        </println>

        <set name='value_2'>10</set>
        <!-- Sample 1 (false) -->
        <println>
            <expr>
                <ne>
                    <value_1 />
                    <value_2 />
                </ne>
            </expr>
        </println>
    </body>
</xsql-script>

4 <gt> function

This function allows you to compare two values. If the first is greater than the second, it will return true. Otherwise, it will return false

<gt>
    <value_1> !
    <value_2> !
</gt>
Example
Copy
<xsql-script name='sample'>
    <body>
        <set name='valor_1'>10</set>
        <set name='valor_2'>20</set>
        <!-- Muestra 0 (false) -->
        <println>
            <expr>
                <gt>
                    <value_1 />
                    <value_2 />
                </gt>
            </expr>
        </println>

        <!-- Sample 1 (true) -->
         <println>
            <expr>
                <gt>
                    <value_2 />
                    <value_1 />
                </gt>
            </expr>
         </println>
    </body>
</xsql-script>

5 <ge> function

This function allows you to compare two values. If the first is greater than or equal to the second, it will return true. Otherwise, it will return false.

<ge>
    <value_1> !
    <value_2> !
</ge>
Example
Copy
<xsql-script name='sample'>
    <body>
        <set name='value_1'>10</set>
        <set name='value_2'>20</set>
        <!-- Sample 0 (false) -->
        <println>
            <expr>
                <ge>
                    <value_1 />
                    <value_2 />
                </ge>
            </expr>
        </println>

        <!-- Sample 1 (true) -->
        <println>
            <expr>
                <ge>
                    <value_2 />
                    <value_1 />
                </ge>
            </expr>
        </println>

        <set name='value_1'>10</set>
        <set name='value_2'>10</set>
        <!-- Sample 1 (true) -->
        <println>
            <expr>
                <ge>
                    <value_1 />
                    <value_2 />
                </ge>
            </expr>
        </println>
    </body>
</xsql-script>

6 <lt> function

This function allows you to compare two values. If the first is less than the second, it will return true. Otherwise, it will return false.

<lt>
    <value_1> !
    <value_2> !
</lt>
Example
Copy
<xsql-script name='sample'>
    <body>
        <set name='value_1'>10</set>
        <set name='value_2'>20</set>
        <!-- Sample 1 (true) -->
        <println>
            <expr>
                <lt>
                    <value_1 />
                    <value_2 />
                </lt>
            </expr>
        </println>

        <!-- Sample 0 (false) -->
         <println>
            <expr>
                <lt>
                    <value_2 />
                    <value_1 />
                </lt>
            </expr>
         </println>
    </body>
</xsql-script>

7 <le> function

This function allows you to compare two values. If the first is less than or equal to the second, it will return true. Otherwise, it will return false.

<le>
    <value_1> !
    <value_2> !
</le>
Example
Copy
<xsql-script name='sample'>
    <body>
        <set name='value_1'>10</set>
        <set name='value_2'>20</set>
        <!-- Sample 1 (true) -->
        <println>
            <expr>
                <le>
                    <value_1 />
                    <value_2 />
                </le>
            </expr>
        </println>

        <!-- Sample 0 (false) -->
        <println>
            <expr>
                <le>
                    <value_2 />
                    <value_1 />
                </le>
            </expr>
        </println>

        <set name='value_1'>10</set>
        <set name='value_2'>10</set>

        <!-- Sample 1 (true) -->
        <println>
            <expr>
                <le>
                    <value_1 />
                    <value_2 />
                </le>
            </expr>
        </println>
    </body>
</xsql-script>