Re: Boolean operators without commutators vs. ALL/ANY - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Boolean operators without commutators vs. ALL/ANY
Date
Msg-id 1308274284-sup-6485@alvh.no-ip.org
Whole thread Raw
In response to Re: Boolean operators without commutators vs. ALL/ANY  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Boolean operators without commutators vs. ALL/ANY
List pgsql-hackers
Excerpts from Tom Lane's message of jue jun 16 17:33:17 -0400 2011:
> Peter Eisentraut <peter_e@gmx.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@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


pgsql-hackers by date:

Previous
From: Hitoshi Harada
Date:
Subject: Re: planinstr, showing planner time on EXPLAIN
Next
From: Mark Kirkwood
Date:
Subject: Re: Re: patch review : Add ability to constrain backend temporary file space