---
title: "Data types and implicit type conversion"
description: "Overview of the CoraDB data types (numeric, date/time, strings, LOBs, collections, JSON, graph) and the rules for implicit type conversion."
url: "https://www.coradb.ai/manual/sql/datatype.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/datatype.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb data types, sql data types, implicit type conversion, type coercion, string to number comparison, coradb types"
---

# Data types and implicit type conversion

CoraDB provides the following groups of data types. Each group is described on its own page.

| Group | Types | Page |
|---|---|---|
| Numeric | SHORT/SMALLINT, INTEGER, BIGINT, NUMERIC/DECIMAL, FLOAT/REAL, DOUBLE | [Numeric types](https://www.coradb.ai/manual/sql/datatype_numeric.html) |
| Date/time | DATE, TIME, TIMESTAMP, DATETIME, and the types WITH TIME ZONE / WITH LOCAL TIME ZONE | [Date/time types](https://www.coradb.ai/manual/sql/datatype_datetime.html) |
| Strings | CHAR, VARCHAR/STRING, BIT, BIT VARYING, ENUM | [String types](https://www.coradb.ai/manual/sql/datatype_string.html) |
| Large objects | BLOB, CLOB | [BLOB/CLOB types](https://www.coradb.ai/manual/sql/datatype_lob.html) |
| Collections | SET, MULTISET, LIST/SEQUENCE | [Collection types](https://www.coradb.ai/manual/sql/datatype_collection.html) |
| JSON | JSON | [JSON data type](https://www.coradb.ai/manual/sql/datatype_json.html) |
| Graph | GRAPH_OBJECT, PATH | [Graph types](https://www.coradb.ai/manual/sql/datatype_graph.html) |

To convert a value explicitly, use [CAST](https://www.coradb.ai/manual/sql/function/typecast_fn.html#cast) or one of the other [type conversion functions](https://www.coradb.ai/manual/sql/function/typecast_fn.html). When an operation combines values of different types without a cast, CoraDB converts them as described below.


## Implicit type conversion

An implicit type conversion is a conversion CoraDB applies on its own when an expression has a different type from the one the operation expects: a value assigned to a column, a function argument, or the operands of a comparison or arithmetic operator.

General rules:

- Collection types (**SET**, **MULTISET**, **LIST**/**SEQUENCE**) are never converted implicitly. Use **CAST**.
- Converting **DATETIME** or **TIMESTAMP** (with or without time zone) to **DATE** or **TIME** drops part of the value. Converting **DATE** to **DATETIME** or **TIMESTAMP** sets the time to midnight (12:00:00 AM).
- Values of the types with a time zone are stored as UTC. Converting them to a type without time zone, or the other way round, uses the session time zone. See [Date/time types](https://www.coradb.ai/manual/sql/datatype_datetime.html#datetime-types).
- Converting a string or an exact numeric value to **FLOAT** or **DOUBLE** can lose precision: strings and exact types are decimal, floating-point types are binary.

### Conversion tables

✓ means that CoraDB converts the type in the row to the type in the column implicitly. An empty cell means that the conversion needs an explicit **CAST**, or is not possible.

**Date/time targets**

| From \ to | DATETIME | DATETIMELTZ | DATETIMETZ | DATE | TIME | TIMESTAMP | TIMESTAMPLTZ | TIMESTAMPTZ |
|---|---|---|---|---|---|---|---|---|
| **DATETIME** | — | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| **DATETIMELTZ** | ✓ | — | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| **DATETIMETZ** | ✓ | ✓ | — | ✓ | ✓ | ✓ | ✓ | ✓ |
| **DATE** | ✓ | ✓ | ✓ | — |  | ✓ | ✓ | ✓ |
| **TIME** |  |  |  |  | — |  |  |  |
| **TIMESTAMP** | ✓ | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ |
| **TIMESTAMPLTZ** | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — | ✓ |
| **TIMESTAMPTZ** | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
| **DOUBLE** |  |  |  |  | ✓ | ✓ | ✓ | ✓ |
| **FLOAT** |  |  |  |  | ✓ | ✓ | ✓ | ✓ |
| **NUMERIC** |  |  |  |  |  | ✓ | ✓ | ✓ |
| **BIGINT** |  |  |  |  | ✓ | ✓ | ✓ | ✓ |
| **INT** |  |  |  |  | ✓ | ✓ | ✓ | ✓ |
| **SHORT** |  |  |  |  | ✓ | ✓ | ✓ | ✓ |
| **BIT** |  |  |  |  |  |  |  |  |
| **VARBIT** |  |  |  |  |  |  |  |  |
| **CHAR** | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| **VARCHAR** | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |


**Numeric values converted to TIME or TIMESTAMP**

- Integer and floating-point values can be converted to **TIME**. The number is taken as seconds, modulo 86,400 (one day): `CAST(90000 AS TIME)` is `01:00:00 AM`. **NUMERIC** values cannot be converted to **TIME**.
- All numeric types, including **NUMERIC**, can be converted to **TIMESTAMP**, **TIMESTAMPLTZ** and **TIMESTAMPTZ**. The number is taken as seconds since 1970-01-01 00:00:00 UTC and cannot exceed 2,147,483,647.

**Numeric, bit string and string targets**

| From \ to | INT | SHORT | BIT | VARBIT | CHAR | VARCHAR | DOUBLE | FLOAT | NUMERIC | BIGINT |
|---|---|---|---|---|---|---|---|---|---|---|
| **DATETIME** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **DATETIMELTZ** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **DATETIMETZ** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **DATE** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **TIME** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **TIMESTAMP** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **TIMESTAMPLTZ** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **TIMESTAMPTZ** |  |  |  |  | ✓ | ✓ |  |  |  |  |
| **DOUBLE** | ✓ | ✓ |  |  | ✓ | ✓ | — | ✓ | ✓ | ✓ |
| **FLOAT** | ✓ | ✓ |  |  | ✓ | ✓ | ✓ | — | ✓ | ✓ |
| **NUMERIC** | ✓ | ✓ |  |  | ✓ | ✓ | ✓ | ✓ | — | ✓ |
| **BIGINT** | ✓ | ✓ |  |  | ✓ | ✓ | ✓ | ✓ | ✓ | — |
| **INT** | — | ✓ |  |  | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| **SHORT** | ✓ | — |  |  | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| **BIT** |  |  | — | ✓ | ✓ | ✓ |  |  |  |  |
| **VARBIT** |  |  | ✓ | — | ✓ | ✓ |  |  |  |  |
| **CHAR** | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ | ✓ | ✓ | ✓ |
| **VARCHAR** | ✓ | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ | ✓ | ✓ |

### Conversion rules

#### INSERT and UPDATE

A value is converted to the type of the column it is assigned to, and rounded or rejected according to that type. Here a string is assigned to the **SHORT** column `units_in_stock` and to the **NUMERIC(10,2)** column `unit_price`:

```sql
UPDATE product SET units_in_stock = '25', unit_price = '31.499' WHERE id = 1618;
SELECT id, unit_price, units_in_stock FROM product WHERE id = 1618;
```

| id | unit_price | units_in_stock |
|---|---|---|
| 1618 | 31.50 | 25 |

#### Functions

When a function expects a given type and the argument can be converted to it, the argument is converted. **MOD** expects numbers, so the two strings are converted to **DOUBLE**:

```sql
SELECT MOD('123', '2') AS m, TYPEOF(MOD('123', '2')) AS t;
```

| m | t |
|---|---|
| 1 | double |

When a function accepts several types and receives a mix, all arguments are converted to the type with the highest priority in its group:

- Date/time: **DATETIME** > **TIMESTAMP** > **DATE** > **TIME**
- Approximate numeric: **DOUBLE** > **FLOAT**
- Exact numeric: **NUMERIC** > **BIGINT** > **INT** > **SHORT**
- String: **CHAR** > **VARCHAR**

#### Comparison operations

The operands of a comparison are converted as follows.

| Operand 1 | Operand 2 | Conversion | Compared as |
|---|---|---|---|
| Numeric | Numeric | none | Number |
| Numeric | String | Operand 2 to **DOUBLE** | Number |
| Numeric | Date/time | Operand 1 to date/time | **TIME**/**TIMESTAMP** |
| String | Numeric | Operand 1 to **DOUBLE** | Number |
| String | String | none | string |
| String | Date/time | Operand 1 to date/time | date/time |
| Date/time | Numeric | Operand 2 to date/time | **TIME**/**TIMESTAMP** |
| Date/time | String | Operand 2 to date/time | date/time |
| Date/time | Date/time | To the type with the higher priority | date/time |

For date/time and numeric operands, the [limits for numeric values converted to TIME or TIMESTAMP](https://www.coradb.ai/manual/sql/datatype.html#number-2-time) apply.

**Exception: string column against a numeric or date/time value.** When operand 1 is a string *column* (or other non-constant expression) and operand 2 is a numeric or date/time *value* (a literal or a host variable), operand 2 is converted to a string and the comparison is a string comparison. The exception does not apply to the set operators (**IN**, **NOT IN**, **= ALL**, **= ANY**, **< ALL**, **< ANY**, **<= ALL**, **<= ANY**, **>= ALL**, **>= ANY**).

Between a numeric value and a string literal, the string is converted to **DOUBLE**:

```sql
SELECT ('2' <= 11) AS a, ('5' > 11) AS b, ('2010-01-01' < DATE'2010-02-02') AS c;
```

| a | b | c |
|---|---|---|
| 1 | 0 | 1 |

An **INT** column compared with a string literal is compared as a number; 1,593 products have an ID below 1603.5:

```sql
SELECT COUNT(*) AS n FROM product WHERE id < '1603.5';
```

| n |
|---|
| 1593 |

`city.postal_code` is a **STRING** column, so comparing it with numbers is a *string* comparison. `'10100'` and `'10785'` sort between `'1000'` and `'1100'`, while a numeric range would not include them:

```sql
SELECT name, postal_code FROM city WHERE postal_code BETWEEN 1000 AND 1100 ORDER BY postal_code;
```

| name | postal_code |
|---|---|
| Buenos Aires | 1010 |
| Torino | 10100 |
| Berlin | 10785 |
| Caracas | 1081 |

The same happens with a numeric host variable, for example `WHERE postal_code BETWEEN ? AND ?` bound to 1000 and 1100. Compare a string column with a quoted string, or convert it explicitly, to get the comparison you intend.

Comparing a **DATE** column with a string literal converts the string to a date, which is the usual way to filter on dates:

```sql
SELECT COUNT(*) AS n FROM orders WHERE order_date >= '2025-12-01';
```

| n |
|---|
| 95 |

#### Range and set comparisons

With the set operators the exception above does not apply, so a numeric column compared with a set of strings is compared numerically:

```sql
SELECT id FROM orders WHERE id <= ALL {'3', '5'} ORDER BY id;
```

| id |
|---|
| 0 |
| 1 |
| 2 |
| 3 |

A string operand that cannot be converted to the other type raises an error.

#### Arithmetic operations

**Date/time operands.** When the operands of `-` are two different date/time types, the one with the lower priority is converted. Here the **DATE** is converted to **DATETIME**, so the result is in milliseconds:

```sql
SELECT DATE'2002-01-01' - DATETIME'2001-02-02 12:00:00 AM' AS ms;
```

| ms |
|---|
| 28771200000 |

**Numeric operands.** Operands of different numeric types are converted to the type with the higher priority. See [Coercion in expressions](https://www.coradb.ai/manual/sql/datatype_numeric.html#coercion-in-expressions).

**Date/time and numeric operands.** With `+` or `-`, the numeric operand is converted to **BIGINT**, **INT** or **SHORT** and counts units of the date/time type: days for **DATE**, seconds for **TIME** and **TIMESTAMP**, milliseconds for **DATETIME**.

**Date/time and string operands.** Only `+` and `-` are allowed.

- With `+`, the string is converted to a **BIGINT** number of units (as above, fractions rounded) and the result has the date/time type.
- With `-`, the string is converted to **DATETIME** (or to **TIME** when the other operand is a **TIME**) and the result is a **BIGINT** difference in milliseconds (seconds for **TIME**).

```sql
SELECT DATE'2002-01-01' + '10' AS plus_days, DATE'2002-01-01' - '2001-01-01' AS diff_ms;
```

| plus_days | diff_ms |
|---|---|
| 2002-01-11 | 31536000000 |

A string that is not a date/time cannot be subtracted:

```sql
SELECT DATE'2002-01-01' - '10';
```

```text
ERROR: Conversion error in timestamp format.
```

**Numeric and string operands.** The string is converted to **DOUBLE** and the result is **DOUBLE**:

```sql
SELECT 4 + '5.2' AS a, TYPEOF(4 + '5.2') AS t;
```

| a | t |
|---|---|
| 9.2 | double |

A string that looks like a date is *not* converted to a date in this case. Use a date literal instead:

```sql
SELECT '2002-01-01' + 1;
```

```text
ERROR: Cannot coerce '2002-01-01' to type double.
```

```sql
SELECT DATE'2002-01-01' + 1 AS next_day;
```

| next_day |
|---|
| 2002-01-02 |

**String operands.** `*`, `/` and `-` between two strings convert both to numbers and return a **DOUBLE**:

```sql
SELECT '3' * '2' AS a, TYPEOF('3' * '2') AS t;
```

| a | t |
|---|---|
| 6 | double |

`+` between two strings depends on the system parameter [plus_as_concat](https://www.coradb.ai/manual/admin/config_sql.html#plus_as_concat):

- `yes` (default): the strings are concatenated, so `'1' + '1'` is `'11'`.
- `no`: if both strings can be converted to numbers they are added as **DOUBLE**, so `'1' + '1'` is `2`.

```sql
SELECT '1' + '1' AS r;
```

| r |
|---|
| 11 |
