Global value/global variable?

Started by Edson Richteralmost 12 years ago3 messagesgeneral
Jump to latest
#1Edson Richter
edsonrichter@hotmail.com

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

#2Ian Lawrence Barwick
barwick@gmail.com
In reply to: Edson Richter (#1)
Re: Global value/global variable?

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ian Lawrence Barwick (#2)
Re: Global value/global variable?

Ian Barwick <ian@2ndquadrant.com> 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