Обсуждение: Is there a way to change current time?

Поиск
Список
Период
Сортировка

Is there a way to change current time?

От
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
Дата:
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.




Re: Is there a way to change current time?

От
Justin Pryzby
Дата:
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
Дата:
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



Re: Is there a way to change current time?

От
Pavel Stehule
Дата:
Hi

čt 15. 4. 2021 v 15:45 odesílatel Warstone@list.ru <warstone@list.ru> napsal:
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
Дата:

select pg_sleep(1);

чт, 15 апр. 2021 г. в 16:45, 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)
 
 
 
 


--
Evgeny Pazhitnov