Re: Global Variables?

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Global Variables?
Date: 2011-10-11 15:08:59
Message-ID: 201110111808.59791.achill@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It would be interesting if the parameters/settings framework could be extended to provide
session/table/user/database level custom settings, accessible via the SET/SHOW/RESET commands.
Is there anything like this ever been considered/discussed ?

Στις Tuesday 11 October 2011 17:06:50 ο/η Eric Radman έγραψε:
> When writing unit tests it's sometimes useful to stub functions such as
> the current date and time
>
> -- define mock functions
> CREATE OR REPLACE FUNCTION _now() RETURNS timestamp with time zone AS $$
> BEGIN RETURN '2011-10-10 10:00'; END;
> $$ LANGUAGE plpgsql;
>
> -- define tables "accounts"
> CREATE TABLE accounts (username varchar, expiration timestamp);
>
> -- populate with sample data
> COPY accounts FROM '/home/eradman/sample_accounts.txt';
>
> -- define view "expired_accounts"
> CREATE OR REPLACE VIEW expired_accounts AS SELECT * FROM accounts WHERE expiration < _now();
>
> -- test views
> SELECT assert(0, (SELECT count(*) FROM expired_accounts)::integer);
>
> Is it possible to declare a global variable that can be referenced from
> the user-defined function _now()? I'm looking for a means of abstraction
> that allows me to avoid issuing CREATE OR REPLACE FUNCTION ... before
> each assert()
>
> current_time := '2012-01-01'::timestamp
> SELECT assert(5, (SELECT count(*) FROM expired_accounts)::integer);
>
> --
> Eric Radman | http://eradman.com
>

--
Achilleas Mantzios

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Forø Tollefsen 2011-10-11 15:12:24 Re: [postgis-users] Query slow down, never completes
Previous Message Sandro Santilli 2011-10-11 15:08:17 Re: [postgis-users] Query slow down, never completes