Thread: Is there a way to change current time?
Hi,
Is there any way to set time that CURRENT_TIMESTAMP and/or now() will give next time? (We need it only for testing purposes so if there is any hack, cheat, etc. It will be fine)
On Thu, Apr 15, 2021 at 04:45:44PM +0300, Warstone@list.ru wrote: > Hi, > > Is there any way to set time that CURRENT_TIMESTAMP and/or now() will give next > time? (We need it only for testing purposes so if there is any hack, cheat, > etc. It will be fine) No, it gets the time from the operating system. -- Bruce Momjian <bruce@momjian.us> https://momjian.us EDB https://enterprisedb.com If only the physical world exists, free will is an illusion.
On Thu, Apr 15, 2021 at 09:58:23AM -0400, Bruce Momjian wrote: > On Thu, Apr 15, 2021 at 04:45:44PM +0300, Warstone@list.ru wrote: > > Hi, > > > > Is there any way to set time that CURRENT_TIMESTAMP and/or now() will give next > > time? (We need it only for testing purposes so if there is any hack, cheat, > > etc. It will be fine) > > No, it gets the time from the operating system. You could overload now(): postgres=# CREATE DATABASE pryzbyj; postgres=# \c pryzbyj pryzbyj=# CREATE SCHEMA pryzbyj; pryzbyj=# CREATE FUNCTION pryzbyj.now() RETURNS timestamp LANGUAGE SQL AS $$ SELECT 'today'::timestamp $$; pryzbyj=# ALTER ROLE pryzbyj SET search_path=pryzbyj,public,pg_catalog; pryzbyj=# SELECT now(); now | 2021-04-15 00:00:00 -- Justin
Bruce Momjian <bruce@momjian.us> writes: > On Thu, Apr 15, 2021 at 04:45:44PM +0300, Warstone@list.ru wrote: >> Is there any way to set time that CURRENT_TIMESTAMP and/or now() will give next >> time? (We need it only for testing purposes so if there is any hack, cheat, >> etc. It will be fine) > No, it gets the time from the operating system. I think there are OS-level solutions for this on some operating systems. If nothing else, you could manually set the system clock; but what you'd really want is for the phony time to be visible to just some processes. regards, tom lane
Hi
Hi,Is there any way to set time that CURRENT_TIMESTAMP and/or now() will give next time? (We need it only for testing purposes so if there is any hack, cheat, etc. It will be fine)
This is a bad way - don't use now() in queries - use a variable instead. Later you can use now as an argument or some constant value.
Regards
Pavel
select pg_sleep(1);
Hi,Is there any way to set time that CURRENT_TIMESTAMP and/or now() will give next time? (We need it only for testing purposes so if there is any hack, cheat, etc. It will be fine)
--
Evgeny Pazhitnov