This function is only relevant for hypertables with integer (as opposed to TIMESTAMP/TIMESTAMPTZ/DATE) time values. For such hypertables, it sets a function that returns the now() value (current time) in the units of the time column. This is necessary for running some policies on integer-based tables. In particular, many policies only apply to chunks of a certain age and a function that returns the current time is necessary to determine the age of a chunk.

NameTypeDescription
main_tableREGCLASSHypertable to set the integer now function for
integer_now_funcREGPROCA function that returns the current time value in the same units as the time column
NameTypeDescription
replace_if_existsBOOLEANWhether to override the function if one is already set. Defaults to false.

To set the integer now function for a hypertable with a time column in unix time (number of seconds since the unix epoch, UTC).

Important

The unix_now function is not immutable by default, and this example could lead to incorrect query results if you are using it with prepared statements or plan caching.

CREATE OR REPLACE FUNCTION unix_now() returns BIGINT LANGUAGE SQL IMMUTABLE as $$ SELECT extract(epoch from now())::BIGINT $$;
SELECT set_integer_now_func('test_table_bigint', 'unix_now');

Keywords

Found an issue on this page?

Report an issue!