Declare an explicit timezone
The most common method of working with timezones is to declare an explicit timezone in the view query.-
Create the view with an explicit timezone
-
Cast to timestamp at query time
Alternatively, you can cast to a timestamp after the view using
SELECT:
Integer-based time
Date and time is usually expressed as year-month-day and hours:minutes:seconds. Most databases use a date/time-type column to express the date and time. However, in some cases, you might need to convert these common time and date formats to a format that uses an integer. The most common integer time is Unix epoch time, which is the number of seconds since the Unix epoch of 1970-01-01, but other types of integer-based time formats are possible. These examples use a calleddevices that contains CPU and disk usage information. The
devices measure time using the Unix epoch.
To create a that uses an integer-based column as time, you need to provide the chunk time
interval. In this case, each chunk is 10 minutes.
-
Create a with an integer time column
Create a and define the integer-based time column and chunk time
interval:
For v2.23.0 and higher, the table is automatically partitioned on the first column in the table with a timestamp data type. If multiple columns are suitable candidates as a partitioning column, throws an error and asks for an explicit definition. For earlier versions, set
partition_columnto a time column. If you are self-hosting v2.20.0 to v2.22.1, to convert your data to the after a specific time interval, you have to call add_columnstore_policy after you call CREATE TABLE If you are self-hosting v2.19.3 and below, create a relational table, then convert it using create_hypertable. You then enable with a call to ALTER TABLE.
set_integer_now_func function. It can be defined as a regular function, but
needs to be STABLE, take no arguments, and return an integer value of the same type as
the time column in the table. When you have set up the time-handling, you can create the .
-
Set up a function to convert the time to the Unix epoch
-
Create the for the
devicestable -
Insert some rows into the table
This command uses the
tablefuncextension to generate a normal distribution, and uses therow_numberfunction to turn it into a cumulative sequence. -
Check that the view contains the correct data