Thread: database name.

database name.

From
Limin Liu
Date:
Hi,

I am new in PostgreSQL and have a simple question:
Is there any way we can find out which db the current client is working
with?

In psql, the prompt tells us the current open db, but I may need to
access that information in a C client on the fly with may db opened.  I
wonder if this is possible?

Thanks in advance.

Limin Liu


Re: database name.

From
Alfred Perlstein
Date:
* Limin Liu <limin@pumpkinnet.com> [001107 19:11] wrote:
> Hi,
>
> I am new in PostgreSQL and have a simple question:
> Is there any way we can find out which db the current client is working
> with?
>
> In psql, the prompt tells us the current open db, but I may need to
> access that information in a C client on the fly with may db opened.  I
> wonder if this is possible?

Yes, please check the docs:


    PQdb Returns the database name of the connection.

    char *PQdb(const PGconn *conn)

    PQdb and the next several functions return the values established at connection. These values are fixed for the
life
    of the PGconn object.

It's described in the 'libpq' section of the programmer's manual.

--
-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]
"I have the heart of a child; I keep it in a jar on my desk."