[MDEV-31672] Behavior of SELECT (CAST 'N/A' AS INT) varys depending on CTE + INSERT Created: 2023-07-12  Updated: 2023-07-12

Status: Open
Project: MariaDB Server
Component/s: Data Manipulation - Insert
Affects Version/s: 10.5.5
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Daniel Challis Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Windows 10, 10.5.5-MariaDB, tested in HeidiSQL and also command line.



 Description   

Please see steps to reproduce as follows....

CREATE TABLE `a` (
`someField` VARCHAR(50) NULL DEFAULT NULL
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;

/* This fails correctly with an INT conversion error (1292)

INSERT INTO A
WITH CTE AS (SELECT CAST(LTRIM(RTRIM('N/A')) AS INT) AS someNumber WHERE CAST(LTRIM(RTRIM('N/A')) AS INT) = 0)
SELECT 'blah' FROM CTE; */

/* but this runs okay with the CAST changing 'N/A' to a 0, only when you attempt any INSERT do you get an error

WITH CTE AS (SELECT CAST(LTRIM(RTRIM('N/A')) AS INT) AS someNumber WHERE CAST(LTRIM(RTRIM('N/A')) AS INT) = 0)
SELECT 'blah' FROM CTE; */

DROP TABLE A;

/* Which one is the preferred behavior? Can we get it consistent please! */


Generated at Thu Feb 08 10:25:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.