Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgejg-0002HN-Ub for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2017 21:46:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cgejf-0005Zb-Uw for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2017 21:46:07 +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 1cgejd-0005YZ-Bu; Wed, 22 Feb 2017 21:46:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cgeja-0007Ob-Ub; Wed, 22 Feb 2017 21:46:03 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v1MLjsJo018673; Wed, 22 Feb 2017 16:45:54 -0500 From: Tom Lane To: Corey Huinker cc: Fabien COELHO , Greg Stark , Erik Rijkers , Robert Haas , Daniel Verite , Jim Nasby , PostgreSQL , pgsql-hackers-owner@postgresql.org Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless) In-reply-to: References: <24063.1486671184@sss.pgh.pa.us> <5095.1486674948@sss.pgh.pa.us> <4fb8635d88c7dc907d069e15fdd1ab94@xs4all.nl> <28640.1487108678@sss.pgh.pa.us> <16856.1487797250@sss.pgh.pa.us> Comments: In-reply-to Corey Huinker message dated "Wed, 22 Feb 2017 16:19:56 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18671.1487799954.1@sss.pgh.pa.us> Date: Wed, 22 Feb 2017 16:45:54 -0500 Message-ID: <18672.1487799954@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Corey Huinker writes: > On Wed, Feb 22, 2017 at 4:00 PM, Tom Lane wrote: >> One thing I'm wondering is why the "active_branch" bool is in "pset" >> and not in the conditional stack. That seems, at best, pretty grotty. >> _psqlSettings is meant for reasonably persistent state. > With the if-stack moved to MainLoop(), nearly all the active_branch checks > could be against a variable that lives in MainLoop(), with two big > exceptions: GetVariable() needs to know when NOT to expand a variable > because it's in a false-block, and get_prompt will need to know when it's > in a false block for printing the '@' prompt hint or equivalent, and pset > is the only global around I know of to do that. Dunno, that sounds a lot like an "if the only tool I have is a hammer, then this must be a nail" argument. pset should not accrete every single global variable in psql just because it's there. Actually, there's a pretty fair amount of stuff in it already that should not be there by any reasonable interpretation of what it's for. Inventing a PsqlFileState or similar struct might be a good idea to help pull some of that cruft out of pset and get it back to having a reasonably clearly defined purpose of holding "current settings". So I think that if you're intent on this being a global variable, it might as well be a standalone global variable. I was wondering more about whether we shouldn't be passing the condition-stack top pointer around to places that need to know about conditional execution. get_prompt would be one if we decide that the prompt might need to reflect this (a question that still seems undecided to me --- I think we'd be better off with "this command was ignored" warning messages). I'm failing to follow why GetVariable would need to care. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers