Skip to main content

Timespan operators

Offsetting operators

Timestamp with time zone operators

An interval can contain hour/minute/second (i.e., fixed length) but not year/month/day (i.e., variable length).

Date and time functions

current_timestamp

Returns the current date and time. current_timestamp is an alias of now. For streaming queries, it can only be used with WHERE, HAVING, and ON clauses. For more information, see Temporal filters. This constraint does not apply to batch queries.

date_part

Extracts the value of a date or timestamp.
precision_string can be year, month, day, hour, minute, second, doy, dow, millisecond, microsecond, epoch, millennium, century, decade, isoyear, quarter, week, isodow, or julian. date/time_value can be a date, timestamp, time, timestamptz, or interval. If date/time_value is timestamptz, it is recommended that time_zone is also specified, otherwise time_zone will default to the session time zone. As date_part() returns values of type double precision, this can result in a loss of precision; therefore, using extract() is recommended.

date_trunc

Truncates a date/time_value to a specified precision_string.
precision_string can be microseconds, milliseconds, second, minute, hour, day, week, month, quarter, year, decade, century, or millennium. date/time_value can be timestamp, timestamptz (i.e., timestamp with time zone), or interval. If date/time_value is timestamptz, it is recommended that time_zone is also specified, otherwise time_zone will default to the session time zone. precision_string value ‘week’ is not supported for interval.

extract

This function has two variants.

extract ( field from source )

Extracts the value of a date or timestamp.
field can be year, month, day, hour, minute, second, doy, dow, millisecond, microsecond, epoch, millennium, century, decade, isoyear, quarter, week, isodow, or julian. source can be the date, timestamp, timestamptz, time, or interval. If time_zone is specified, source should be of type timestamptz.

extract( epoch )

Converts the value of timestamp with time zone to Unix epoch seconds (the number of seconds since 1970-01-01 00:00:00 UTC). Negative for timestamps prior to that.

make_date

Creates date from year, month, and day fields.

make_time

Creates time from hour, minute, and seconds fields.

make_timestamp

Creates timestamp from year, month, day, hour, minute, and seconds fields.

now

Returns the current date and time. For streaming queries, now() can only be used in WHERE, HAVING, ON (join conditions), and FROM (e.g., GENERATE_SERIES) clauses. For more information, see Temporal filters. This constraint does not apply to batch queries.

proctime

Returns the system time with time zone when a record is processed. You can use this function to specify the processing time of a record in a table or source.

to_char

Converts the input to string according to the given format. Both uppercase and lowercase formats are supported.

to_date

Converts a string to a date according to the given format.

to_timestamp

This function has two variants.

to_timestamp ( seconds_double_precision )

Converts Unix epoch seconds (the number of seconds since 1970-01-01 00:00:00+00) to timestamptz.

to_timestamp ( string, timestamp_format )

Converts a string to timestamptz according to the given format.

Template patterns for date / time formatting

For date and time formatting functions like to_char, to_timestamp, and to_date, the format needs to be specified by using the supported template patterns. Any text that is not a template pattern is simply copied verbatim. Please see the table below for the template patterns supported in RisingWave.

Delaying execution functions

The following functions are available to delay execution of the current session’s process.

pg_sleep

The pg_sleep() function makes the current session’s process sleep until the given number of seconds have elapsed. Fractional-second delays can be specified.

pg_sleep_for

pg_sleep_for is a convenience function to allow the sleep time to be specified as an interval.