Re: Freezing localtimestamp and other time function on some value

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>
Cc: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Freezing localtimestamp and other time function on some value
Date: 2016-04-12 11:47:55
Message-ID: CAFj8pRCaf-GHSQajHavAw1o+ppwp2efOuzDzXmTQox+M4VMVrg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

2016-04-12 12:50 GMT+02:00 Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>:

> Hello!
> Is there any method to freeze localtimestamp and other time function value.
> Say after freezing on some value sequential calls to these functions give
> you the same value over and over again.
> This is useful primarily for testing.
>
> In oracle there is alter system set fixed_date command. Have Postgres this
> functionality?
>

It is not possible in Postgres

PostgreSQL solution is using working time as function parameter. This
parameter can have default value.

postgres=# select test('2016-03-10 10:00:00');

NOTICE: current time is: 2016-03-10 10:00:00

postgres=# select test();
NOTICE: current time is: 2016-04-12 13:47:21.644488

postgres=# select test();
NOTICE: current time is: 2016-04-12 13:47:22.633711

CREATE OR REPLACE FUNCTION public.test(t timestamp without time zone
DEFAULT now())
RETURNS void
LANGUAGE plpgsql
AS $function$
BEGIN
RAISE NOTICE 'current time is: %', t;
END;
$function$

Regards

Pavel

>
> --
> Alex Ignatov
> Postgres Professional: http://www.postgrespro.com
> The Russian Postgres Company
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Petr Korobeinikov 2016-04-12 12:11:27 Re: Freezing localtimestamp and other time function on some value
Previous Message Petr Korobeinikov 2016-04-12 11:31:59 Re: Freezing localtimestamp and other time function on some value