Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eftBg-00020U-Sr for pgsql-bugs@arkaria.postgresql.org; Sun, 28 Jan 2018 20:04:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eftBf-0003VU-KY for pgsql-bugs@arkaria.postgresql.org; Sun, 28 Jan 2018 20:04:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eftBf-0003VL-BO for pgsql-bugs@lists.postgresql.org; Sun, 28 Jan 2018 20:04:23 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eftBc-0001K9-LW for pgsql-bugs@lists.postgresql.org; Sun, 28 Jan 2018 20:04:22 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1eftBa-0001gI-Oz; Sun, 28 Jan 2018 15:04:18 -0500 Date: Sun, 28 Jan 2018 15:04:18 -0500 From: Bruce Momjian To: Tom Lane Cc: akos@elegran.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15025: PSQL CLI - inconsistency when both -d and -U supplies a username Message-ID: <20180128200418.GA4380@momjian.us> References: <20180123130013.7407.24749@wrigleys.postgresql.org> <20180128034832.GD9153@momjian.us> <29202.1517168326@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <29202.1517168326@sss.pgh.pa.us> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Jan 28, 2018 at 02:38:46PM -0500, Tom Lane wrote: > Bruce Momjian writes: > > psql -d "postgresql://user2@momjian.us/test" -U user1 > > --> Password for user user1: > > but it wants the user2 password. > > > It doesn't matter whether -U is first or last, it always prompts for the > > -U user, but connects as the -d user. > > Bleah. > > > Because the URI is parsed by libpq, I don't think we can do any better > > than just suppress the user name in the password prompt when a URI is > > used. > > That doesn't seem very user-friendly at all. I think that the most > correct behavior in this case would be to throw an error because of the > conflicting command line parameters. Now admittedly, psql doesn't throw > an error for > > psql -U alice -U bob > > so maybe just silently making a choice is OK, but we need to be clear > as to which choice we made. Isn't it possible to get the URI parse > results back out of libpq? Well, there is PQuser(), but you need to pass a connection struct to that, and before you connect you don't have one. libpq's conninfo_uri_parse_options() is a static function so that can't be used. I don't see any libpq documentation saying that URIs override command-line specifications. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription +