From: | Eric Ridge <ebr(at)tcdi(dot)com> |
---|---|
To: | Ron St-Pierre <rstpierre(at)syscor(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to determine current database? |
Date: | 2004-02-13 23:52:29 |
Message-ID: | AF22FD0E-5E7F-11D8-984A-000A95BB5944@tcdi.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
> majordomo(at)postgresql(dot)org
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-02-14 00:41:23 | Re: How to determine current database? |
Previous Message | Joe Conway | 2004-02-13 23:51:05 | Re: How to determine current database? |