[MDEV-9302] Different field types for equivalent NULLIF and IF vs CASE with AVG(int_field) and 0e0 arguments Created: 2015-12-18  Updated: 2015-12-18  Resolved: 2015-12-18

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.0, 10.1
Fix Version/s: 10.0.23

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

This script:

DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (c1 INT DEFAULT NULL);
INSERT INTO t1 (c1) VALUES (1),(2),(3),(4);
CREATE TABLE t2
SELECT
  NULLIF(AVG(c1),0e0) AS c1,
  IF(AVG(c1)=0e0,NULL,AVG(c1)) AS c2,
  CASE WHEN AVG(c1)=0e0 THEN 0e0 ELSE AVG(c1) END AS c3
FROM t1;
SHOW CREATE TABLE t2;

returns

+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `c1` decimal(14,4) DEFAULT NULL,
  `c2` decimal(14,4) DEFAULT NULL,
  `c3` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+

All three columns should be of the same data type.



 Comments   
Comment by Alexander Barkov [ 2015-12-18 ]

Oops. There was a mistake in the script.
The correct script is:

DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (c1 INT DEFAULT NULL);
INSERT INTO t1 (c1) VALUES (1),(2),(3),(4);
CREATE TABLE t2
SELECT
  NULLIF(AVG(c1),0e0) AS c1,
  IF(AVG(c1)=0e0,NULL,AVG(c1)) AS c2,
  CASE WHEN AVG(c1)=0e0 THEN NULL ELSE AVG(c1) END AS c3
FROM t1;
SHOW CREATE TABLE t2;

and it does return an expected result.

Generated at Thu Feb 08 07:33:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.