TIME

On this page Carat arrow pointing down

New in v2.0: The TIME data type stores the time of day without a time zone.

Aliases

In CockroachDB, the following are aliases:

  • TIME WITHOUT TIME ZONE

Syntax

A constant value of type TIME can be expressed using an interpreted literal, or a string literal annotated with type TIME or coerced to type TIME.

The string format for time is HH:MM:SS.SSSSSS. For example: TIME '05:40:00.000001'.

CockroachDB also supports using uninterpreted string literals in contexts where a TIME value is otherwise expected.

The fractional portion of TIME is optional and is rounded to microseconds (i.e., six digits after the decimal) for compatibility with the PostgreSQL wire protocol.

Size

A TIME column supports values up to 8 bytes in width, but the total storage size is likely to be larger due to CockroachDB metadata.

Example

icon/buttons/copy
> CREATE TABLE time (a INT PRIMARY KEY, b TIME);
icon/buttons/copy
> SHOW COLUMNS FROM time;
+-------+------+-------+---------+-------------+
| Field | Type | Null  | Default |   Indices   |
+-------+------+-------+---------+-------------+
| a     | INT  | false | NULL    | {"primary"} |
| b     | TIME | true  | NULL    | {}          |
+-------+------+-------+---------+-------------+
icon/buttons/copy
> INSERT INTO time VALUES (1, TIME '05:40:00');
icon/buttons/copy
> SELECT * FROM time;
+---+---------------------------+
| a |             b             |
+---+---------------------------+
| 1 | 0000-01-01 05:40:00+00:00 |
+---+---------------------------+
Note:
The cockroach sql shell displays the date and timezone due to the Go SQL driver it uses. Other client drivers may behave similarly. In such cases, however, the date and timezone are not relevant and are not stored in the database.

Supported Casting & Conversion

TIME values can be cast to any of the following data types:

Type Details
INTERVAL Converts to the span of time since midnight (00:00)
STRING Converts to format 'HH:MM:SS.SSSSSS' (microsecond precision)

See Also


Yes No
On this page

Yes No