pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Corey Huinker <corey.huinker@gmail.com>
Cc: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Greg Stark <stark@mit.edu>
Cc: Erik Rijkers <er@xs4all.nl>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Daniel Verite <daniel@manitou-mail.org>
Cc: Jim Nasby <Jim.Nasby@bluetreble.com>
Cc: PostgreSQL <pgsql-hackers@postgresql.org>
Cc: pgsql-hackers-owner@postgresql.org
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: Sun, 12 Mar 2017 15:29:37 -0400
Message-ID: <21200.1489346977@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYsV+hLf_hDXrudpLR0DjGrVhDCCSHJQUbUACXCvHbqkg@mail.gmail.com>
References: <CADkLM=dcMHeSOQZv0Dd8AO4cM+OzADg7u8PcA7d8pNezmLDo=g@mail.gmail.com>
	<CADkLM=c_DDcUXadhfPL4Qcb9QxWbwP6OW_pL=TffLGw=PDiWPQ@mail.gmail.com>
	<alpine.DEB.2.20.1702240729060.21598@lancre>
	<CADkLM=edWn9Kfj10BUAr4VTkLxAmkAc_u0_6AfjHTBC6phmhRQ@mail.gmail.com>
	<alpine.DEB.2.20.1702260807540.10344@lancre>
	<CADkLM=dwGETiOV=3J=7JGM=acoMRgHz2CnrETek-wdYYE6AuJQ@mail.gmail.com>
	<CADkLM=eLwZHnK82E=qtLMxWy_UDJe-XUMUK1xABPgSP386H4Qw@mail.gmail.com>
	<alpine.DEB.2.20.1703010851190.762@lancre>
	<CADkLM=fCuLWGxEqmWrOk2tZWEi0bAU6xO58+O5-VxLWpnFFhoA@mail.gmail.com>
	<alpine.DEB.2.20.1703011742300.762@lancre>
	<CADkLM=eeyM_5eFyty6S_VDK-rJXNaKPJmB5mELC04n1xfWZK=Q@mail.gmail.com>
	<alpine.DEB.2.20.1703020710260.762@lancre>
	<CADkLM=e9BY_-PT96mcs4qqiLtt8t-Fp=e_AdycW-aS0OQvbC9Q@mail.gmail.com>
	<alpine.DEB.2.20.1703021042470.21981@lancre>
	<CADkLM=e3vpXixqQd9X_wD0LVL1vkrq4oPu33xzsTr3CokSRnWA@mail.gmail.com>
	<alpine.DEB.2.20.1703030709210.12372@lancre>
	<alpine.DEB.2.20.1703030723050.12372@lancre>
	<1! 3293.1489279510@sss.pgh.pa.us>
	<CAKFQuwZBtDy3xjvcQSeEjeGT_mO5bxsyo2qbzr4S7GC72Yro1w@mail.gmail.com>
	<CADkLM=dez7vVv80fFOr_MFsJcVZM9AOcRUDGUFpRX87OwU7b6w@mail.gmail.com>
	<17014.1489339469@sss.pgh.pa.us>
	<CAKFQuwYsV+hLf_hDXrudpLR0DjGrVhDCCSHJQUbUACXCvHbqkg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> There are only four commands and a finite number of usage permutations.
> Enumerating and figuring out the proper behavior for each should be done.

> Thus - ​If the expressions are bad they are considered false but the block
> is created

> If the flow-control command is bad the system will tell the user why and
> how to get back to a valid state - the entire machine state goes INVALID
> until a corrective command is encountered.

> For instance:

> \if
> \else
> \elif
> warning: elif block cannot occur directly within an \else block.  either
> start a new \if, \endif the current scope, or type \else to continue
> entering commands into the existing else block.  no expression evaluation
> has occurred.
> \echo 'c'
> warning: command ignored in broken \if block scope - see prior correction
> options

This is looking a whole lot like the overcomplicated error reporting that
we already considered and rejected.  I think it's sufficient to print
something like "\elif is not allowed to follow \else; command ignored"
and not change state.  We're not really helping anybody by going into
an "invalid machine state" AFAICS, and having such a thing complicates
the mental model more than I'd like.

A different way of looking at this problem, which will seem like overkill
right now but would absolutely not be once you consider looping, is that
what should happen when we see \if is that we do nothing but absorb text
until we see the matching \endif.  At that point we could bitch and throw
everything away if, say, there's \elif after \else, or anything else you
want to regard as a "compile time error".  Otherwise we start execution,
and from there on it probably has to behave as we've been discussing.
But this'd be pretty unfriendly from an interactive standpoint, and I'm
not really convinced that it makes for significantly better error
reporting.

			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



view thread (232+ messages)  latest in thread

Message-ID: <21200.1489346977@sss.pgh.pa.us>
Permalink:  ../21200.1489346977@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21200.1489346977@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, corey.huinker@gmail.com, coelho@cri.ensmp.fr, stark@mit.edu, er@xs4all.nl, robertmhaas@gmail.com, daniel@manitou-mail.org, Jim.Nasby@bluetreble.com, pgsql-hackers-owner@postgresql.org
  Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
  In-Reply-To: <21200.1489346977@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox