Custom session variables?

Started by Adam Richabout 19 years ago6 messagesgeneral
Jump to latest
#1Adam Rich
adam.r@sbcglobal.net

Is there any way to define custom variables per session scope?
In oracle, we do this using package variables.

Basically when a user logs into our application, it generates one-time
session information that we want to make available to all the procedures
and triggers, without passing it directly (even if that were possible
with
triggers).

Is inserting/selecting data from temporary tables the only way to
accomplish this ?

#2Kenneth Downs
ken@secdat.com
In reply to: Adam Rich (#1)
Re: Custom session variables?

Adam Rich wrote:

Is there any way to define custom variables per session scope?
In oracle, we do this using package variables.

This would be so cool to have.

--
Kenneth Downs
Secure Data Software, Inc.
www.secdat.com / www.andromeda-project.org
Office: 631-689-7200 Cell: 631-379-0010

::Think you may have a problem with programming? Ask yourself this
::question: do you worry about how to throw away a garbage can?

#3David Fetter
david@fetter.org
In reply to: Adam Rich (#1)
Re: Custom session variables?

On Fri, Mar 02, 2007 at 01:53:28PM -0600, Adam Rich wrote:

Is there any way to define custom variables per session scope?

You can have them in PL/Perl(U), PL/Tcl(U) and PL/PythonU and other
such PLs, and you can create SQL accessors for them.

Cheers,
D
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!
Consider donating to PostgreSQL: http://www.postgresql.org/about/donate

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: David Fetter (#3)
Re: Custom session variables?

David Fetter <david@fetter.org> writes:

On Fri, Mar 02, 2007 at 01:53:28PM -0600, Adam Rich wrote:

Is there any way to define custom variables per session scope?

You can have them in PL/Perl(U), PL/Tcl(U) and PL/PythonU and other
such PLs, and you can create SQL accessors for them.

Another possibility is the "customized GUC options" route: you can take
advantage of the fact that the backend will let you set variables that
don't exist yet, if they are in a namespace that postgresql.conf says
is OK.
http://www.postgresql.org/docs/8.2/static/runtime-config-custom.html
This approach probably doesn't scale nicely to a whole lotta values,
but for a dozen or so strings it'd work well enough.

regards, tom lane

#5Adam Rich
adam.r@sbcglobal.net
In reply to: Tom Lane (#4)
Re: Custom session variables?

Any way to pull the value of a config variable
into a pl/pgsql variable?

Show quoted text

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Friday, March 02, 2007 3:46 PM
To: David Fetter
Cc: Adam Rich; pgsql-general@postgresql.org
Subject: Re: [GENERAL] Custom session variables?

David Fetter <david@fetter.org> writes:

On Fri, Mar 02, 2007 at 01:53:28PM -0600, Adam Rich wrote:

Is there any way to define custom variables per session scope?

You can have them in PL/Perl(U), PL/Tcl(U) and PL/PythonU and other
such PLs, and you can create SQL accessors for them.

Another possibility is the "customized GUC options" route:
you can take
advantage of the fact that the backend will let you set variables that
don't exist yet, if they are in a namespace that postgresql.conf says
is OK.
http://www.postgresql.org/docs/8.2/static/runtime-config-custom.html
This approach probably doesn't scale nicely to a whole lotta values,
but for a dozen or so strings it'd work well enough.

regards, tom lane

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Adam Rich (#5)
Re: Custom session variables?

"Adam Rich" <adam.r@sbcglobal.net> writes:

Any way to pull the value of a config variable
into a pl/pgsql variable?

current_setting(), or select from the pg_settings view.

regards, tom lane