Re: Freezing localtimestamp and other time function on some value

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Freezing localtimestamp and other time function on some value
Дата
Msg-id CAKFQuwYSQS2A1y1=9+HqBxPjn-F2M0GvqU04M-nHUQLVPeFciw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Freezing localtimestamp and other time function on some value  (Alex Ignatov <a.ignatov@postgrespro.ru>)
Ответы Re: Freezing localtimestamp and other time function on some value  (Alex Ignatov <a.ignatov@postgrespro.ru>)
Список pgsql-general
On Tue, Apr 12, 2016 at 8:37 AM, Alex Ignatov <a.ignatov@postgrespro.ru> wrote:

On 12.04.2016 18:01, Adrian Klaver wrote:

>>I do it by having the date be one of the function arguments and have the default be something like current_date. When I test I supply a date to override the default. This allows for testing the various scenarios by changing the supplied date.

With that approach you have to say application programmer - 'Hey dude, please edit this piece of code for my purpose and after that rollback it'.  I think that it is unacceptable in large project...

​CREATE FUNCTION do_some_date_based_stuff(reference_date date, other_args) [...]

CREATE FUNCTION production_wrapper_for_above(other_args) [...]
AS $$
SELECT do_some_date_based_stuff(now(), other_args);
$$​;

Easy to test do_some_date_based_stuff since it has fewer if any external dependencies.  Shouldn't need to test the wrapper that simply calls the "do_some..." with a default value of the current date.

You might be able to define an appropriate function signature that avoids having to write the wrapper though regardless there is no need to have a different environment for testing versus production if approached in this manner.  You just need to decide on the most desirable way to make it work.

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Table seems empty but its size is in gigabytes
Следующее
От: Alex Ignatov
Дата:
Сообщение: Re: Freezing localtimestamp and other time function on some value