From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | jac(at)uol(dot)cz |
Subject: | BUG #16545: COALESCE evaluates arguments to the right of the first non-null argument |
Date: | 2020-07-16 13:09:49 |
Message-ID: | 16545-affff840bc4e72ca@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 16545
Logged by: Petr Jac
Email address: jac(at)uol(dot)cz
PostgreSQL version: 12.3
Operating system: docker(at)ubuntu20(dot)04
Description:
Hello,
after upgrading PostgreSQL from 10 to 11 I have found out different
behaviour of COALESCE function.
It seems to me that it became to evaluate arguments to the right of the
first non-null argument which is in contradiction with documentation:
>"Like a CASE expression, COALESCE only evaluates the arguments that are
needed to determine the result; that is, arguments to the right of the first
non-null argument are not evaluated. This SQL-standard function provides
capabilities similar to NVL and IFNULL, which are used in some other
database systems."
I can demonstrate this with example running in pure docker postgres
instances:
### PostgreSQL 10.13
postgres=# SELECT version();
version
------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 10.13 (Debian 10.13-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled
by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
(1 row)
postgres=# SELECT coalesce((SELECT 'ONE'),
(SELECT 'TWO'
WHERE '123' ~
((xpath('/tag/text()','<tag>[</tag>'))[1]::TEXT)
)
);
coalesce
----------
ONE
(1 row)
### PostgreSQL 11.8
postgres=# SELECT version();
version
----------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 11.8 (Debian 11.8-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled
by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
(1 row)
postgres=# SELECT coalesce((SELECT 'ONE'),
(SELECT 'TWO'
WHERE '123' ~
((xpath('/tag/text()','<tag>[</tag>'))[1]::TEXT)
)
);
ERROR: invalid regular expression: brackets [] not balanced
### PostgreSQL 12.3
postgres=# SELECT version();
version
------------------------------------------------------------------------------------------------------------------
PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled
by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
(1 row)
postgres=# SELECT coalesce((SELECT 'ONE'),
(SELECT 'TWO'
WHERE '123' ~
((xpath('/tag/text()','<tag>[</tag>'))[1]::TEXT)
)
);
ERROR: invalid regular expression: brackets [] not balanced
---
Thank you
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2020-07-16 14:14:42 | Re: BUG #16545: COALESCE evaluates arguments to the right of the first non-null argument |
Previous Message | Michael Paquier | 2020-07-16 07:19:01 | Re: BUG #16526: pg_test_fsync in v12 doesn't run in Windows |