Re: Re : [GENERAL] Global value/global variable?

2014-06-19 Thread Edson Richter
I've ended creating a table to store database parameters, and using a subquery, 
I can achieve the "global variable" effect.
Thanks for your insight,
Edson.

From: edsonrich...@hotmail.com
To: pgsql-general@postgresql.org
Subject: Re : [GENERAL] Global value/global variable?
Date: Thu, 19 Jun 2014 14:39:45 +

Yes. It's similar, but consider I'm using a connection pool, so I''ve no 
control on when the connections are established/destroyed.I think I need 
something with scope broader than session... Atenciosamente,

Edson Richter 

-- Mensagem original --
De: John McKown
Data: 19/06/2014 8h44
Para: Edson Richter;
Assunto:Re: [GENERAL] Global value/global variable?

A psql session is shown below:
tsh009=# \set lpar '\'LIH1\''tsh009=# select * from capped where lpar=:lpar 
limit 5; lpar |   started   |ended
--+-+- LIH1 | 2014-06-09 21:57:13 | 
2014-06-09 22:21:21 LIH1 | 2014-06-09 22:42:12 | 2014-06-09 23:06:22 LIH1 | 
2014-06-09 23:22:12 | 2014-06-09 23:39:12
 LIH1 | 2014-06-09 23:52:12 | 2014-06-10 00:01:21 LIH1 | 2014-06-10 01:07:11 | 
2014-06-10 01:07:51(5 rows)

Is this close to what you are looking for?


On Wed, Jun 18, 2014 at 9:50 PM, Edson Richter  wrote:




It is possible to define a global value/variable in PostgreSQL in a way that I 
can use it in any query/view/function?For example, I do have a connection 
string I use for dblink connections in several places (specially, inside views).
Then, if I want to change the connection string, I do have to change every view 
manually.If I can set a kind of global variable, then I just use it inside 
every view - then, at my application startup (or even at PostgreSQL startup, if 
I can set this string at postgresql.conf level), would set this "global 
variable" to point the current string.

Your enlightment will be really welcome.
Regards,
Edson
  


-- 
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan

Maranatha! <><

John McKown



  

Re : [GENERAL] Global value/global variable?

2014-06-19 Thread Edson Richter
Yes. It's similar, but consider I'm using a connection pool, so I''ve no control on when the connections are established/destroyed.I think I need something with scope broader than session... Atenciosamente,Edson Richter -- Mensagem original --De: John McKownData: 19/06/2014 8h44Para: Edson Richter;Assunto:Re: [GENERAL] Global value/global variable?A psql session is shown below:tsh009=# \set lpar '\'LIH1\''tsh009=# select * from capped where lpar=:lpar limit 5; lpar |   started   |    ended    
--+-+- LIH1 | 2014-06-09 21:57:13 | 2014-06-09 22:21:21 LIH1 | 2014-06-09 22:42:12 | 2014-06-09 23:06:22 LIH1 | 2014-06-09 23:22:12 | 2014-06-09 23:39:12
 LIH1 | 2014-06-09 23:52:12 | 2014-06-10 00:01:21 LIH1 | 2014-06-10 01:07:11 | 2014-06-10 01:07:51(5 rows)Is this close to what you are looking for?
On Wed, Jun 18, 2014 at 9:50 PM, Edson Richter <edsonrich...@hotmail.com> wrote:



It is possible to define a global value/variable in PostgreSQL in a way that I can use it in any query/view/function?For example, I do have a connection string I use for dblink connections in several places (specially, inside views).
Then, if I want to change the connection string, I do have to change every view manually.If I can set a kind of global variable, then I just use it inside every view - then, at my application startup (or even at PostgreSQL startup, if I can set this string at postgresql.conf level), would set this "global variable" to point the current string.
Your enlightment will be really welcome.Regards,Edson 		 	   		  
-- There is nothing more pleasant than traveling and meeting new people!Genghis KhanMaranatha! <><
John McKown




Re: [GENERAL] Global value/global variable?

2014-06-18 Thread Tom Lane
Ian Barwick  writes:
> On 19/06/14 11:50, Edson Richter wrote:
>> It is possible to define a global value/variable in PostgreSQL in a way that 
>> I can use it in any query/view/function?

> There's no such thing as a global variable, but why not use a table
> to store any global configuration values?

Actually, people do regularly (ab)use custom GUC variables for this
purpose.  But a table is not a bad solution.  The GUC solution does
not scale to more than order-of-a-hundred values.

regards, tom lane


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Global value/global variable?

2014-06-18 Thread Ian Barwick

On 19/06/14 11:50, Edson Richter wrote:

It is possible to define a global value/variable in PostgreSQL in a way that I 
can use it in any query/view/function?
For example, I do have a connection string I use for dblink connections in 
several places (specially, inside views).
Then, if I want to change the connection string, I do have to change every view 
manually.
If I can set a kind of global variable, then I just use it inside every view - then, at 
my application startup (or even at PostgreSQL startup, if I can set this string at 
postgresql.conf level), would set this "global variable" to point the current 
string.

Your enlightment will be really welcome.


There's no such thing as a global variable, but why not use a table
to store any global configuration values? You can always do something like this:

  SELECT dblink_connect('myconn', (select connstr from dblink_conf))


Regards

Ian Barwick

--
 Ian Barwick   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Global value/global variable?

2014-06-18 Thread Edson Richter
It is possible to define a global value/variable in PostgreSQL in a way that I 
can use it in any query/view/function?For example, I do have a connection 
string I use for dblink connections in several places (specially, inside 
views).Then, if I want to change the connection string, I do have to change 
every view manually.If I can set a kind of global variable, then I just use it 
inside every view - then, at my application startup (or even at PostgreSQL 
startup, if I can set this string at postgresql.conf level), would set this 
"global variable" to point the current string.
Your enlightment will be really welcome.
Regards,
Edson