Re: Global Variables?

From: Eric Radman <ericshane(at)eradman(dot)com>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Global Variables?
Date: 2011-10-11 19:53:15
Message-ID: 20111011195315.GA14540@SDF.ORG
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Oct 11, 2011 at 04:26:47PM +0200, Alban Hertroys wrote:
> On 11 October 2011 16:06, Eric Radman <ericshane(at)eradman(dot)com> wrote:
> > When writing unit tests it's sometimes useful to stub functions such
> > as the current date and time
>
> You could create a table for such "constants" and read your
> current-time from that table.
>
> Additionally, I would put such stub functions in a separate schema and
> create a test role with that schema as the top of their search_path.
>
> That way, you could even override system function implementations (and
> other definitions) and only have them apply to the role you're using
> for unit testing.

> CREATE ROLE unit_tester;
> CREATE SCHEMA unit_tests AUTHORIZATION unit_tester;
> SET search_path TO unit_tests, my_schema, public;
>
> CREATE TABLE unit_test_parameters (
> current_time timestamp without time zone NOT NULL DEFAULT now()
> );

Excellent advice; this model works wonderfully. pg_catalog is normally
implicit, but you're right, system functions can be overridden by
setting the search path.

Eric Radman | http://eradman.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Java Services 2011-10-11 19:54:54 how to call a stored function from another stored function? even possible?
Previous Message John R Pierce 2011-10-11 19:52:11 Re: libpq 8.3 and 8.4 interfaces