473,889 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*******@postg resql.org

Nov 22 '05 #1
4 31438
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*******@postg resql.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_databa se()" returns the current database
name.

=# select current_databas e();
current_databas e
------------------
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*******@postg resql.org

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

Nov 22 '05 #3
Ron St-Pierre <rs*******@sysc or.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_databas e():
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_databa se()" returns the current
database name.

=# select current_databas e();
current_databas e
------------------
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
2207
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 appending a tag, such as MYDATABASE_BLOB001, ..._BLOB002 etc. Thanks.
0
1522
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 database to be given a different name so that it will be obvious that it is an archive copy and so that the new empty database will continue with the original name. Any help will be greatly appreciated. Thanks.
3
1737
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 ***** Public Sub CompactDB()
1
9087
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
10731
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, ccell.dbo.atrib_os.os FROM
10
8284
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 other words, I need to write code that makes a copy of the current database and saves it with a new name. I've read that it is a bad idea to copy a file that is currently in use so I am at a loss of what I should do. Any suggestions?
2
1649
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 join sysindexes i on (o. = i.) where o. like 'sys%'and i.indid=1
1
7100
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 context? By database context, I mean the current database selected by the last USE or the default database for the user. This may sound dumb (heck, don't you know the last USE statement you issued?) but I'm trying to debug a multi-threaded application...
2
1867
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 Password, and Permissions to allow or restrict the access of users and Groups to the objects in a specific Database file, (Ex: for only Sales.mdb) it creates security password for all (*.mdb) files. Some DB files donít need any type of security...
0
9969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9810
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10794
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10896
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7999
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4650
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3257
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.