473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to determine current database?

I am using postgres 7.3.4 and need to be able to determine which
database a query is being run in (from a script). pg_database lists
databases but doesn't tell me which one is currently active. Is there a
query I can use along the lines of:
UPDATE tblUpdates SET xxx=1234 WHERE pg_current = TRUE;
or
UPDATE tblUpdates SET xxx=1234 WHERE pg_current = thisDBname;

We have about 15 databases all set up identically and when the structure
changes I run scripts to update them to ensure that they are all the
same. I need to create two new databases which have slight changes
(different default values - for now) and want to be able to have my
scripts be able to determine which database their running from.

Thanks

Ron
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 22 '05 #1
4 31416
Ron St-Pierre wrote:
I am using postgres 7.3.4 and need to be able to determine which
database a query is being run in (from a script). pg_database lists
databases but doesn't tell me which one is currently active.


See:
http://www.postgresql.org/docs/7.3/s...ions-misc.html

HTH,

Joe

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #2
On Feb 13, 2004, at 6:05 PM, Ron St-Pierre wrote:
I am using postgres 7.3.4 and need to be able to determine which
database a query is being run in (from a script). pg_database lists
databases but doesn't tell me which one is currently active. Is there
a query I can use along the lines of:
The built-in function "current_database()" returns the current database
name.

=# select current_database();
current_database
------------------
testing
(1 row)

Use it in your update statements too.

eric
UPDATE tblUpdates SET xxx=1234 WHERE pg_current = TRUE;
or
UPDATE tblUpdates SET xxx=1234 WHERE pg_current = thisDBname;

We have about 15 databases all set up identically and when the
structure changes I run scripts to update them to ensure that they are
all the same. I need to create two new databases which have slight
changes (different default values - for now) and want to be able to
have my scripts be able to determine which database their running
from.

Thanks

Ron
---------------------------(end of
broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to
ma*******@postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 22 '05 #3
Ron St-Pierre <rs*******@syscor.com> writes:
I am using postgres 7.3.4 and need to be able to determine which
database a query is being run in (from a script).


See current_database():
http://www.postgresql.org/docs/7.4/s...ions-misc.html

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 22 '05 #4
Eric Ridge wrote:
On Feb 13, 2004, at 6:05 PM, Ron St-Pierre wrote:
I am using postgres 7.3.4 and need to be able to determine which
database a query is being run in (from a script). pg_database lists
databases but doesn't tell me which one is currently active. Is there
a query I can use along the lines of:

The built-in function "current_database()" returns the current
database name.

=# select current_database();
current_database
------------------
testing
(1 row)

Use it in your update statements too.

eric


That's exactly what I need!

Joe Conway wrote:
See:
http://www.postgresql.org/docs/7.3/s...ions-misc.html

Thanks guys. I was searching the docs looking for functions starting
with pg_

Ron
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robin Tucker | last post by:
Is there an sp_zzzzzz function to return the name of the current database? I would like to use this name as a variable in a stored procedure in order to create names for further databases (by...
0
by: Nasos | last post by:
I want to have a command button which enables the user to make a copy of the current database, but without any records in it. Of course all the forms and reports will be intact. I want the old...
3
by: Paul T. Rong | last post by:
Dear all, My aim is to compact and repair current database, I got the following code from http://www.mvps.org/access/general/gen0041.htm Option Compare Database ' ***** Code Start *****...
1
by: Najm | last post by:
Hi All, I am facing this issue very frist time. I add a logical device as following: USE master GO EXEC sp_addumpdevice 'disk', 'AdvWorksData',
1
by: Tiago Gigli | last post by:
Guys, 1st of all.. sorry about my english ok? Im from Brazil... Im trying to get a RS connecting through 2 databases with the query below: SELECT scar..osbalcao.numeroos,...
10
by: Janelle.Dunlap | last post by:
In the database that I am creating I need to be able to rename the file with a name that the user specifies using the Save As Dialog window (I already have the code that brings up this window). In...
2
by: ssingh | last post by:
Hello, I want to select the names and number of rows of all tables in the current database, whose name starts with 'sys' my query is: select o., sum(i.) as numbers from sysobjects o inner...
1
by: Shift4SMS | last post by:
This is probably an easy one but I'm banging my head against the wall trying to sculpture the perfect Google search. Anyway... Is there a way to determine the current connection's database...
2
by: plaguna | last post by:
I have MS Access 2007 (My Database files are saved as .mdb extension). I have no problem to create Users and Groups, and grant them specific Permissions. What I don’t understand is why when I create...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.