Unix Technical Forum

How populate : variables dynamically?

This is a discussion on How populate : variables dynamically? within the pgsql Novice forums, part of the PostgreSQL category; --> I can't find a way to do something in PostgreSQL that I am used to in Oracle: How can ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:24 PM
Doug
 
Posts: n/a
Default How populate : variables dynamically?

I can't find a way to do something in PostgreSQL that I am used to in
Oracle:
How can I populate a variable in psql that can be used in subsequent
places in the same session, by SELECTing a value?

Here's an example in Oracle:
SET VERIFY OFF LINESIZE 132
COLUMN OSID NEW_VALUE ORACLE_SID NOPRINT;
COLUMN SCHEMA_VALUE NEW_VALUE SCHEMA NOPRINT;
COLUMN INSTANCEVERSION NEW_VALUE ORACLE_VERSION NOPRINT;
-- COLUMN MON_YY NEW_VALUE MONYY NOPRINT;
SELECT SYS_CONTEXT('USERENV','DB_NAME') AS OSID FROM DUAL;
SELECT USER AS SCHEMA_VALUE FROM DUAL;
SELECT VERSION AS INSTANCEVERSION FROM V
$INSTANCE;
DEFINE OWNER=&&SCHEMA

PROMPT ORACLE_SID IS &&ORACLE_SID
PROMPT SCHEMA IS &&SCHEMA
PROMPT ORACLE_VERSION IS &&ORACLE_VERSION

SELECT '&&ORACLE_SID' AS ORASID, '&&ORACLE_VERSION' AS ORAVER,
'&&SCHEMA' AS CURRUSER FROM DUAL;


Here's the output from running it:
ORACLE_SID IS NC9I
SCHEMA IS DBMAINT
ORACLE_VERSION IS 9.2.0.6.0

ORASID ORAVER
CURRUSER
-------------------------------- --------------------------------
--------------------------------
NC9I 9.2.0.6.0
DBMAINT

The point is to populate session variables dynamically using a select
statement
and then be able to use them more than once during the same session.
Some of these could be put in the Oracle login.sql so the values are
always available.

What I can not find is how to populate ':' variables in PostgreSQL
like this. Is this supported, and I just haven't found the
documentation
that describes how to do it?

Thanks for your help.
--doug

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:50 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com