Re: binary operators on integers

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Marko Kreen <marko(at)l-t(dot)ee>, pgsql-patches(at)postgresql(dot)org
Subject: Re: binary operators on integers
Date: 2001-01-19 21:30:09
Message-ID: 200101192130.QAA12409@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Looks like this is fixed:

test=> select 5 & ~ 6;
ERROR: Unable to identify a right operator '&' for type 'int4'
You may need to add parentheses or an explicit cast
test=> select 5 & (~ 6);
?column?
----------
1
(1 row)

> This patch was installed, with xor as "#". The parser still needs work.
> Besides the known issue of "|", this also parses funny:
>
> => select 5 & ~ 6;
> ERROR: Unable to identify a right operator '&' for type 'int4'
>
>
> Marko Kreen writes:
>
> > Here is my next take on binary operators for integers.
> > It implements the following operators for int2/int4/int8:
> >
> > ~ - not
> > & - and
> > ^ - xor
> > | - or
> > << - shift left
> > >> - shift right
> >
> > Notes:
> >
> > * My original choice for xor was '#' because the '^' operator conflicts
> > with power operator on floats but Tom Lane said:
> >
> > > Well, you *could* use '^' since there's no definition of it for integer
> > > operands. But that would mean that something like '4^2', which was
> > > formerly implicitly coerced to float and interpreted as floating
> > > power function, would suddenly mean something different. Again a
> > > serious risk of silently breaking applications. This doesn't apply to
> > > '|' though, since it has no numeric interpretation at all right now.
> >
> > As the bit-string uses '^' too for xor-ing it would be nice to be
> > consistent. I am quite unsure on this matter. The patch now seems
> > otherwise sane to me, this is the only issue left.
> >
> > * On << and >> the second argument is always int32 as this seems
> > to be the 'default' int type in PostgreSQL.
> >
> > * Oids used are 1874 - 1909.
> >
> > Comments?
> >
> > Patch is against current CVS.
> >
> >
>
> --
> Peter Eisentraut peter_e(at)gmx(dot)net http://yi.org/peter-e/
>
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2001-01-19 21:43:12 Re: "initdb -t" destroys all databases
Previous Message Bruce Momjian 2001-01-19 20:59:41 Re: Small patch to replace 'idle' by 'trans' if transaction is still open

Browse pgsql-patches by date

  From Date Subject
Next Message Marko Kreen 2001-01-20 15:31:28 Re: binary operators on integers
Previous Message Bruce Momjian 2001-01-19 20:59:41 Re: Small patch to replace 'idle' by 'trans' if transaction is still open