bit|varbit #, xor operator

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: bit|varbit #, xor operator
Date: 2016-10-16 19:25:24
Message-ID: 2826f2a9-f622-2572-8132-4083cf0a3f42@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Related to [1], I want to add an operator that returns the count of set
(or unset) bits in a bit|varbit input. Given the number of times people
ask "how can I get a count of NULL fields" and similar, I expect this to
become quite popular. The obvious choice would be to use #, but I was
rather surprised to discover # is already used for XOR.

I think ^ is a pretty standard convention for XOR, but I can understand
why we wouldn't want to just use that. But I also think the choice of #
is pretty unfortunate.

# is currently mixed between XOR and counting[2]. IMHO we should
disambiguate it. My bet is that the XOR versions are very seldom used
and could be renamed without much grumbling. The versions that actually
do counting are presumably more popular. I'm not sure about the
intersection versions.

Personally I think it was a mistake to use # for intersection. Range
doesn't do that (using * instead), and AFAICT PostGIS doesn't either
(preferring &). So I propose renaming those operators, as well as the
XOR ones. I think ^^ is pretty logical for XOR. I'm not sure about
intersect... * doesn't seem like a good idea, && is overlaps, maybe &*.

Related to this I'd also like to add a boolean XOR operator as that's a
relatively common request/question.

1:
https://www.postgresql.org/message-id/9f1db94a-fa18-5975-3a6c-6850fabb3865%40BlueTreble.com
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532) mobile: 512-569-9461

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2016-10-16 19:35:40 Re: VACUUM's ancillary tasks
Previous Message Jim Nasby 2016-10-16 19:03:21 Question on "record type has not been registered"