Is there a way to change current time?
Is there a way to change current time?
От:
Warstone@list.ru <warstone@list.ru>
Дата:
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)
Re: Is there a way to change current time?
От:
Bruce Momjian <bruce@momjian.us>
Дата:
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 https://momjian.us EDB https://enterprisedb.com If only the physical world exists, free will is an illusion.
Re: Is there a way to change current time?
От:
Justin Pryzby <pryzby@telsasoft.com>
Дата:
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
Re: Is there a way to change current time?
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Bruce Momjian 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
Re: Is there a way to change current time?
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
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
Re: Is there a way to change current time?
От:
Eugene Pazhitnov <pazhitnov@gmail.com>
Дата:
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