> For the complete documentation index, see [llms.txt](https://upsolver.gitbook.io/content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://upsolver.gitbook.io/content/reference-1/functions-and-operators/operators/logical.md).

# Logical

## Logical operators <a href="#id1" id="id1"></a>

<table><thead><tr><th width="214.33333333333331">Operator</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>AND</code></td><td>True if both values are true</td><td><code>a AND b</code></td></tr><tr><td><code>OR</code></td><td>True if either value is true</td><td><code>a OR b</code></td></tr><tr><td><code>NOT</code></td><td>True if the value is false</td><td><code>NOT a</code></td></tr></tbody></table>

## Effect of `NULL` on logical operators <a href="#effect-of-null-on-logical-operators" id="effect-of-null-on-logical-operators"></a>

### `AND`

The result of an `AND` comparison may be `NULL` if one or both sides of the expression are `NULL`.&#x20;

If, however, at least one side of an `AND` operator is `FALSE`, then the expression evaluates to `FALSE`.

#### Transformation job example

**SQL**

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true	
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT 
        null::boolean AND true AS and_example1,
        null::boolean AND false AS and_example2,
        null::boolean AND null::boolean AS and_example3
    FROM default_glue_catalog.upsolver_samples.orders_raw_data 
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;
```

{% hint style="info" %}
Note that the example above casts `null` as a `Boolean` since using an untyped null is not currently supported and logical operators expect `Boolean` inputs.
{% endhint %}

Query result:

| and\_example1 | and\_example2 | and\_example3 |
| ------------- | ------------- | ------------- |
| `null`        | false         | `null`        |

### `OR`

The result of an `OR` comparison may be `NULL` if one or both sides of the expression are `NULL`.&#x20;

If, however, at least one side of an `OR` operator is `TRUE` the expression evaluates to `TRUE`.

#### Transformation job example

**SQL**

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true	
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT 
        null::boolean OR null::boolean AS or_example1,
        null::boolean OR false AS or_example2,
        null::boolean OR true AS or_example3
    FROM default_glue_catalog.upsolver_samples.orders_raw_data 
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;
```

Query result:

| or\_example1 | or\_example2 | or\_example3 |
| ------------ | ------------ | ------------ |
| `null`       | `null`       | true         |

### `AND` and `OR` truth table

The following truth table demonstrates the handling of `NULL` in `AND` and `OR`:

<table><thead><tr><th>a</th><th width="172">b</th><th>a AND b</th><th>a OR b</th></tr></thead><tbody><tr><td><code>TRUE</code></td><td><code>TRUE</code></td><td><code>TRUE</code></td><td><code>TRUE</code></td></tr><tr><td><code>TRUE</code></td><td><code>FALSE</code></td><td><code>FALSE</code></td><td><code>TRUE</code></td></tr><tr><td><code>TRUE</code></td><td><code>NULL</code></td><td><code>NULL</code></td><td><code>TRUE</code></td></tr><tr><td><code>FALSE</code></td><td><code>TRUE</code></td><td><code>FALSE</code></td><td><code>TRUE</code></td></tr><tr><td><code>FALSE</code></td><td><code>FALSE</code></td><td><code>FALSE</code></td><td><code>FALSE</code></td></tr><tr><td><code>FALSE</code></td><td><code>NULL</code></td><td><code>FALSE</code></td><td><code>NULL</code></td></tr><tr><td><code>NULL</code></td><td><code>TRUE</code></td><td><code>NULL</code></td><td><code>TRUE</code></td></tr><tr><td><code>NULL</code></td><td><code>FALSE</code></td><td><code>FALSE</code></td><td><code>NULL</code></td></tr><tr><td><code>NULL</code></td><td><code>NULL</code></td><td><code>NULL</code></td><td><code>NULL</code></td></tr></tbody></table>

### `NOT`

The logical complement of `NULL` is `NULL` as shown in the following example with a transformation job.

**SQL**

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true	
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT 
        NOT null::boolean AS not_example
    FROM default_glue_catalog.upsolver_samples.orders_raw_data 
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;
```

Query result:

| not\_example |
| ------------ |
| null         |

### `NOT` truth table

The following truth table demonstrates the handling of `NULL` in `NOT`:

| a       | NOT a   |
| ------- | ------- |
| `TRUE`  | `FALSE` |
| `FALSE` | `TRUE`  |
| `NULL`  | `NULL`  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://upsolver.gitbook.io/content/reference-1/functions-and-operators/operators/logical.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
