---
title: Boolean and numeric literals in query strings
---

A literal value is one that is explicitly defined in code rather than computed or derived from other values. In the Deephaven Query Language (DQL), you use literals to define constant values in expressions. This guide covers boolean and numeric literals in [query strings](./query-string-overview.md).

[Query strings](./query-string-overview.md) use Java syntax for literals, which can differ from Groovy's. For example, an unsuffixed decimal such as `3.14` is a `double` in a [query string](./query-string-overview.md) but a `BigDecimal` in [Groovy](./groovy-variables.md#scalars). The engine also departs from Java in a few cases, described under [Numeric literals](#numeric-literals).

## Boolean literals

In DQL, there are only two boolean literal values: `true` and `false` (lowercase).

The following code uses both boolean literals, then shows the column types with [`meta`](../reference/table-operations/metadata/meta.md):

```groovy order=source,sourceMeta
source = emptyTable(1).update("TrueLiteral = true", "FalseLiteral = false")
sourceMeta = source.meta()
```

In `sourceMeta`, both columns are `java.lang.Boolean`, the type Deephaven uses for boolean columns.

## Numeric literals

Numeric literals in DQL can be integers or floating-point numbers. By default, the engine treats an integer literal as a 32-bit signed integer ([Java primitive](./data-types.md#primitive-types) `int`) and a floating-point literal as a 64-bit floating-point number ([Java primitive](./data-types.md#primitive-types) `double`).

Java rejects an integer literal that is too large for an `int`. The engine makes it a `long` instead. For a hexadecimal or binary literal, the engine compares the unsigned value with the `int` maximum, so `0xFFFFFFFF` is the `long` 4294967295, not the `int` -1 that Java produces.

Java reads an integer literal with a leading zero, such as `0777`, as octal. The query language does not support octal literals, so the engine rejects an integer literal with a leading zero. Write `777` for the decimal value, or a hexadecimal literal such as `0x1FF` for the same bits.

You can specify the type of a numeric literal by appending a suffix to the number:

- `L` or `l` for a 64-bit signed integer ([Java primitive](./data-types.md#primitive-types) `long`).
- `f` or `F` for a 32-bit floating-point number ([Java primitive](./data-types.md#primitive-types) `float`).
- `d` or `D` for a 64-bit floating-point number ([Java primitive](./data-types.md#primitive-types) `double`). This suffix is optional on a literal that already has a decimal point or exponent, since `double` is the default there. On a whole number, `5d` is a `double`, while `5` is an `int`.

Groovy's `G` and `I` suffixes are not valid in DQL. A [query string](./query-string-overview.md) that uses either one fails to compile.

Numeric literals can also be written in these forms:

- **Hexadecimal**: prefix the digits with `0x` or `0X`, as in `0xABCD` (43981).
- **Binary**: prefix the digits with `0b` or `0B`, as in `0b1010` (10).
- **Scientific notation**: use `e` or `E` for a decimal exponent, as in `1.23e3` (1230.0).
- **Hexadecimal floating point**: use `p` or `P` for a binary exponent after `0x`-prefixed hexadecimal digits, as in `0x1.23p3` (9.09375).
- **Underscores**: place `_` between digits for readability, as in `1_000_000`. The underscores don't change the value.

The following example constructs a column for each default type, suffix, and form above, then shows the table metadata with [`meta`](../reference/table-operations/metadata/meta.md):

```groovy order=source,sourceMeta
source = emptyTable(1).update(
    "IntLiteral = 5",
    "IntHexadecimalLiteral = 0xABCD",
    "IntBinaryLiteral = 0b1010",
    "LongLiteral = 123456789L",
    "PromotedLongLiteral = 3000000000",
    "PromotedHexadecimalLiteral = 0xFFFFFFFF",
    "FloatLiteral = 3.14f",
    "DoubleLiteral = 3.14",
    "DoubleSuffixLiteral = 5d",
    "FloatScientificLiteral = 1.23e3f",
    "DoubleScientificLiteral = 1.23e3",
    "FloatHexadecimalLiteral = 0x1.23p3f",
    "DoubleHexadecimalLiteral = 0x1.23p3",
    "IntUnderscoreLiteral = 1_000_000",
    "LongUnderscoreLiteral = 500_000_000L",
    "FloatUnderscoreLiteral = 9_876.543_210f",
    "DoubleUnderscoreLiteral = 1_232.815_679",
)
sourceMeta = source.meta()
```

In `sourceMeta`, each column's type follows the rules above. `PromotedLongLiteral` and `PromotedHexadecimalLiteral` have no suffix, but they are `long` columns because their values are too large for an `int`. `DoubleSuffixLiteral` is a `double` column. In `source`, `PromotedHexadecimalLiteral` holds 4294967295.

## Related documentation

- [Query string overview](./query-string-overview.md)
- [String and char literals](./string-char-literals.md)
- [Date-time literals](./date-time-literals.md)
- [Data types](./data-types.md)
- [Casting](./casting.md)
- [Groovy variables in query strings](./groovy-variables.md)
- [`emptyTable`](../reference/table-operations/create/emptyTable.md)
- [`meta`](../reference/table-operations/metadata/meta.md)
- [`update`](../reference/table-operations/select/update.md)
