Re: bitwise and/or aggregate functions?

Lists: pgsql-hackers
From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: bitwise and/or aggregate functions?
Date: 2004-04-27 16:24:56
Message-ID: Pine.LNX.4.58.0404271807140.28436@sablons.cri.ensmp.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Dear hackers,

still in the spirit of "it may be useful to others, as it was to me, and
it does cost very little", and before submitting a small patch and being
exploded because it is obviously very stupid:

Would it be appropriate to contribute BIT_AND and BIT_OR aggregates
for integer types, with some documentation and minimal validation?
There has been a discussion recently on pgsql-general about that.

1) mysql has them... it seems to be an argument here around sometimes;-)
it is in their proud list-of-features that it has and that postgresql
does not have.

2) each declaration is a 4-line "CREATE AGGREGATE", the underlying
functions being already available for & and | operators.

3) I know that one can add them if they are needed, but what
would be the point of NOT providing such simple features, and
having the basic user to have to learn about creating aggregate
functions and browse a long time in the documentation for that?

I needed them for some application: I'm happy I know how to add them now,
but I would have been even happier if I had found them just available
without having to learn about these intesting details about postgresql
extensions.

Have a nice day,

--
Fabien Coelho - coelho(at)cri(dot)ensmp(dot)fr


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-04-27 17:51:26
Message-ID: 200404271751.i3RHpQk15212@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fabien COELHO wrote:
>
> Dear hackers,
>
> still in the spirit of "it may be useful to others, as it was to me, and
> it does cost very little", and before submitting a small patch and being
> exploded because it is obviously very stupid:
>
> Would it be appropriate to contribute BIT_AND and BIT_OR aggregates
> for integer types, with some documentation and minimal validation?
> There has been a discussion recently on pgsql-general about that.
>
> 1) mysql has them... it seems to be an argument here around sometimes;-)
> it is in their proud list-of-features that it has and that postgresql
> does not have.
>
> 2) each declaration is a 4-line "CREATE AGGREGATE", the underlying
> functions being already available for & and | operators.
>
> 3) I know that one can add them if they are needed, but what
> would be the point of NOT providing such simple features, and
> having the basic user to have to learn about creating aggregate
> functions and browse a long time in the documentation for that?
>
> I needed them for some application: I'm happy I know how to add them now,
> but I would have been even happier if I had found them just available
> without having to learn about these intesting details about postgresql
> extensions.

I am confused why you would use bit on integers when there is a bit type
with an AND operator:

pg_catalog | & | bit | bit | bit | bitwise and

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-04-28 06:46:09
Message-ID: Pine.LNX.4.58.0404280836130.28436@sablons.cri.ensmp.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> > Would it be appropriate to contribute BIT_AND and BIT_OR aggregates
>
> I am confused why you would use bit on integers

Well, (I think) I need them to manipulate pg_catalog's aclitem bitfields.
I plea not guilty for the design of pg_catalog;-)
Moreover, I added aclitem accessors which return INT4 in a recent patch
that you kindly applied.

> when there is a bit type with an AND operator:
> pg_catalog | & | bit | bit | bit | bitwise and

Sure. "&" is also available for all integer types.
BTW, I'm arguing about AGGREGATE functions, and there is no aggregate
functions at the time, neither for int* nor for bit.

SELECT BIT_OR(aclitem_privs(...)) AS effective_privs
FROM ...
WHERE aclitem_grantee(...)=... AND ... ;

Or maybe I cannot understand why you're confused?

--
Fabien Coelho - coelho(at)cri(dot)ensmp(dot)fr


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-04-28 07:07:59
Message-ID: 408F584F.7000905@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> SELECT BIT_OR(aclitem_privs(...)) AS effective_privs
> FROM ...
> WHERE aclitem_grantee(...)=... AND ... ;

Is there anything in SQL2003 about such operators? If there is, we
should make sure we use the correct aggregate names.

Chris


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-04-28 08:08:07
Message-ID: Pine.LNX.4.58.0404280957280.28436@sablons.cri.ensmp.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> > SELECT BIT_OR(aclitem_privs(...)) AS effective_privs
> > FROM ...
> > WHERE aclitem_grantee(...)=... AND ... ;
>
> Is there anything in SQL2003 about such operators? If there is, we
> should make sure we use the correct aggregate names.

That's a point!

I thought of BIT_* because it is short and also used by mysql.
Ingres has BIT_AND and BIT_OR functions, but they are not aggregates.

I don't know where these standards are available online... It seems they
are not available:-(

--
Fabien Coelho - coelho(at)cri(dot)ensmp(dot)fr


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>, Neil Conway <neilc(at)samurai(dot)com>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-04-28 08:18:24
Message-ID: 408F68D0.10204@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>>Is there anything in SQL2003 about such operators? If there is, we
>>should make sure we use the correct aggregate names.
>
> That's a point!
>
> I thought of BIT_* because it is short and also used by mysql.
> Ingres has BIT_AND and BIT_OR functions, but they are not aggregates.
>
> I don't know where these standards are available online... It seems they
> are not available:-(

Neil - can you check your SQL2003 copy to see if it mentions standard
aggregates on bit types?

Thanks,

Chris


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>, Neil Conway <neilc(at)samurai(dot)com>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-04-28 09:58:16
Message-ID: Pine.LNX.4.58.0404281153050.28436@sablons.cri.ensmp.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> > I thought of BIT_* because it is short and also used by mysql.
> > Ingres has BIT_AND and BIT_OR functions, but they are not aggregates.
> >
> > I don't know where these standards are available online... It seems they
> > are not available:-(
>
> Neil - can you check your SQL2003 copy to see if it mentions standard
> aggregates on bit types?

I haven't seen such a function in the "draft" standard I have found.
It seems it is not yet available from INCITS.

There are also EVERY (= aggregate AND) and SOME/ANY (= aggregate OR) for
booleans, that are interesting. I'll add them with the patch. However I
think that I may need to add two small functions for that.

--
Fabien Coelho - coelho(at)cri(dot)ensmp(dot)fr


From: Alvaro Herrera Munoz <alvherre(at)dcc(dot)uchile(dot)cl>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-05-18 13:08:49
Message-ID: 20040518130849.GC1208@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, May 18, 2004 at 12:39:08PM -0400, Neil Conway wrote:

> A copy that claims to "represent an almost indistinuishable delta on the
> actual SQL 2003 database standard" is available online here:
>
> http://www.wiscorp.com/sql/sql_2003_standard.zip

Those are PDFs AFAIR, not easily greppable ... do you have a text version,
or do you always look up things by looking at the TOC? I'm not thrilled
with the idea of reading all 1500 pages of it ...

--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
"El día que dejes de cambiar dejarás de vivir"


From: Neil Conway <neilc(at)samurai(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-05-18 16:39:08
Message-ID: 40AA3C2C.5070908@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

[ Sorry for the latency of my response, Chris -- this got buried in my
inbox... ]

Fabien COELHO wrote:
>>>I don't know where these standards are available online... It seems they
>>>are not available:-(

A copy that claims to "represent an almost indistinuishable delta on the
actual SQL 2003 database standard" is available online here:

http://www.wiscorp.com/sql/sql_2003_standard.zip

>>Neil - can you check your SQL2003 copy to see if it mentions standard
>>aggregates on bit types?

I couldn't see any mention of any aggregates specific to the bit types,
although my ability to accurately divine information from the standard
has been less than perfect in the past. There are the EVERY() and ANY()
aggregates that Fabien mentioned, though.

-Neil


From: Neil Conway <neilc(at)samurai(dot)com>
To: Alvaro Herrera Munoz <alvherre(at)dcc(dot)uchile(dot)cl>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-05-18 17:53:03
Message-ID: 40AA4D7F.5020109@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera Munoz wrote:
> Those are PDFs AFAIR, not easily greppable

Not greppable, but any half-decent PDF viewer should have a "search"
feature that should allow much the same thing. Checking the index is
another way to go, although it is somewhat time-consuming.

I don't have access to an ASCII version (of SQL2003; I believe I've got
an ASCII copy of SQL92 around here somewhere).

-Neil


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-05-19 00:38:19
Message-ID: 9682.1084927099@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Neil Conway <neilc(at)samurai(dot)com> writes:
> Fabien COELHO wrote:
>> Neil - can you check your SQL2003 copy to see if it mentions standard
>> aggregates on bit types?

> I couldn't see any mention of any aggregates specific to the bit types,

There certainly are none, since in fact SQL2003 removes the BIT types
entirely. See Annex E:

2) ISO/IEC 9075-2:1999 defined data types called BIT and BIT VARYING.
These data types have been deleted from this edition of ISO/IEC 9075.

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Neil Conway <neilc(at)samurai(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bitwise and/or aggregate functions?
Date: 2004-05-19 01:16:13
Message-ID: 200405190116.i4J1GDD01435@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Neil Conway <neilc(at)samurai(dot)com> writes:
> > Fabien COELHO wrote:
> >> Neil - can you check your SQL2003 copy to see if it mentions standard
> >> aggregates on bit types?
>
> > I couldn't see any mention of any aggregates specific to the bit types,
>
> There certainly are none, since in fact SQL2003 removes the BIT types
> entirely. See Annex E:
>
> 2) ISO/IEC 9075-2:1999 defined data types called BIT and BIT VARYING.
> These data types have been deleted from this edition of ISO/IEC 9075.

Understand. To me, allowing bitwise and boolean aggregates on a column
seemed like a natural capability we should have.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073