Re: Boolean operators without commutators vs. ALL/ANY

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Florian Pflug <fgp(at)phlo(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Boolean operators without commutators vs. ALL/ANY
Date: 2011-06-17 01:42:43
Message-ID: 1308274284-sup-6485@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Excerpts from Tom Lane's message of jue jun 16 17:33:17 -0400 2011:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > I don't really agree that visual correlation needs to trump everything.
> > If say
> > foo =~ bar
> > and
> > foo ~= bar
> > were to produce completely different results, this would introduce bugs
> > all over the place.
>
> Huh? That's about like arguing that standard mathematical notation is
> broken because a < b and a > b don't produce the same result.

The difference is that the mnemonic for > and < is very simple and in
widespread knowledge; not something I would say for =~'s rule of "the ~
is on the side of the regexp". I know I used to get it wrong in Perl
(i.e. I wrote ~= occasionally).
To make matters worse, our delimiters for regexes are the same as for
strings, the single quote. So you get

foo =~ 'bar' /* foo is the text column, bar is the regex */
'bar' =~ foo /* no complaint but it's wrong */

'bar' ~= foo /* okay */
'foo' ~= bar /* no complaint but it's wrong */

How do I tell which is the regex here? If we used, say, /, that would
be a different matter:

foo =~ /bar/
/bar/ ~= foo /* both okay */

If we had that and you get it wrong, the parser would immediately barf
at you if you got it wrong:

/bar/ =~ foo /* wrong: LHS wanted text, got regex */
foo ~= /bar/ /* wrong: LHS wanted regex, got text */

(Note: I'm not suggesting we use / as delimiter. This is just an
example.)

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Kirkwood 2011-06-17 01:51:37 Re: Re: patch review : Add ability to constrain backend temporary file space
Previous Message Hitoshi Harada 2011-06-17 01:10:08 Re: planinstr, showing planner time on EXPLAIN