BUG #14385: Operator IS changed priority in 9.5

Started by Strahinja Kustudićover 9 years ago2 messagesbugs
Jump to latest
#1Strahinja Kustudić
strahinjak@nordeus.com

The following bug has been logged on the website:

Bug reference: 14385
Logged by: Strahinja Kustudic
Email address: strahinjak@nordeus.com
PostgreSQL version: 9.5.4
Operating system: CentOS 6
Description:

If we create a test table like this:

test-# create table test (i integer, b boolean);

And insert the following data:

test-# insert into test (i) values (5), (null);
test-# update test set b = i is not null;

When we run the following select on Postgres 9.1-9.4:
test-# select
test-# 'aaa' || i is not null || 'bbb' as v1,
test-# 'aaa' || b || 'bbb' as v2,
test-# 'aaa' || i is not null || 'bbb' = 'aaa' || b || 'bbb' as v1_eq_v2
test-# from test;
v1 | v2 | v1_eq_v2
-------------+-------------+----------
aaatruebbb | aaatruebbb | t
aaafalsebbb | aaafalsebbb | t
(2 rows)

but if we run the same query on 9.5 we get a different output:

test-# select
test-# 'aaa' || i is not null || 'bbb' as v1,
test-# 'aaa' || b || 'bbb' as v2,
test-# 'aaa' || i is not null || 'bbb' = 'aaa' || b || 'bbb' as v1_eq_v2
test-# from test;
v1 | v2 | v1_eq_v2
----------+-------------+----------
truebbb | aaatruebbb | f
falsebbb | aaafalsebbb | f
(2 rows)

As you can see 9.5 removes the first 'aaa' string from concatenation. We
guess it's because of the operator IS priority has changed in 9.5, because
if we put 'i is not null' between parenthesis, it works like before 9.5:

test-# select
test-# 'aaa' || (i is not null) || 'bbb' as v1,
test-# 'aaa' || b || 'bbb' as v2,
test-# 'aaa' || (i is not null) || 'bbb' = 'aaa' || b || 'bbb' as
v1_eq_v2
test-# from test;
v1 | v2 | v1_eq_v2
-------------+-------------+----------
aaatruebbb | aaatruebbb | t
aaafalsebbb | aaafalsebbb | t
(2 rows)

We couldn't find any documentation changes about this, so is this a bug, or
was it intentional?

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Strahinja Kustudić
strahinjak@nordeus.com
In reply to: Strahinja Kustudić (#1)
Re: BUG #14385: Operator IS changed priority in 9.5

You can ignore this bug, since it's not a bug. We found it in the official
documentation https://www.postgresql.org/docs/9.5/static/release-9-5.html
once we reported it.

At first we thought it was a bug with the '||' operator, so we couldn't
find it in the documentation, then while we were reporting it we realized
it is a change in operator precedence. We mostly checked the
https://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.5 for new
changes, but in there it wasn't mention.

Sorry about this and thanks for the operator_precedence_warning, it will
help a lot.