Re: libpq analog of \c - Mailing list pgsql-general

From Adrian Klaver
Subject Re: libpq analog of \c
Date
Msg-id 399b41f6-c78a-4088-ae49-92a47a325975@aklaver.com
Whole thread
In response to Re: libpq analog of \c  (Igor Korot <ikorot01@gmail.com>)
Responses Re: libpq analog of \c
List pgsql-general
On 10/5/26 7:57 AM, Igor Korot wrote:
> Hi,
> 
> 
> 
> On Sun, Oct 4, 2026, 11:35 PM Laurenz Albe <laurenz.albe@cybertec.at 
> <mailto:laurenz.albe@cybertec.at>> wrote:
> 
>     On Sun, 2026-10-04 at 23:09 -0700, Igor Korot wrote:
>      > What do  issue in the libpq interface to
>      > select the current database?
> 
>     You cannot select the current database.  A database connection remains
>     connected to the same database for the entire time of the connection.
>     You'll have to do what psql does: connect to the second database, and
>     if that succeeds, disconnect from the first one.
> 
> 
> Where do I look for that code?

https://github.com/postgres/postgres/blob/master/src/bin/psql/command.c

As a starting point, section beginning with:

/*
  * \c or \connect -- connect to database using the specified parameters.
  *
  * \c [-reuse-previous=BOOL] dbname user host port

...
> 
> Thank you.
> 
> 
>     Yours,
>     Laurenz Albe
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com



pgsql-general by date:

Previous
From: Igor Korot
Date:
Subject: Re: libpq analog of \c
Next
From: Igor Korot
Date:
Subject: Re: libpq analog of \c