From 52883b109b3dbb2d9ee2b0a40bd629c30a6f72ba Mon Sep 17 00:00:00 2001 From: ChangRui-Ryan Date: Tue, 4 Nov 2025 17:56:57 +0800 Subject: [PATCH 1/2] MySQL compatibility about decimal insert through jdbc --- develop/dev-guide-sample-application-java-jdbc.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/develop/dev-guide-sample-application-java-jdbc.md b/develop/dev-guide-sample-application-java-jdbc.md index dac1223ec6ba0..108e3a0f47f23 100644 --- a/develop/dev-guide-sample-application-java-jdbc.md +++ b/develop/dev-guide-sample-application-java-jdbc.md @@ -282,6 +282,17 @@ Unless you need to write complex SQL statements, it is recommended to use [ORM]( - Reduce [boilerplate code](https://en.wikipedia.org/wiki/Boilerplate_code) for managing connections and transactions. - Manipulate data with data objects instead of a number of SQL statements. +### MySQL compatibility + +When you insert data into a `DECIMAL` column, if the number of decimal places exceeds the defined scale, MySQL performs a `TRUNCATE` operation and inserts the data successfully, regardless of how many extra decimal places there are. + +In TiDB v8.5.3 and earlier versions: + +- If the number of decimal places exceeds the column's defined scale but does not exceed 72, TiDB also performs a `TRUNCATE` operation and inserts the data successfully. +- However, if the number of decimal places exceeds 72, the write operation fails and returns an error. + +Starting from TiDB v8.5.4, TiDB's behavior aligns with that of MySQL: regardless of the number of excess decimal places, it performs a `TRUNCATE` operation and inserts the data successfully. + ## Next steps - Learn more usage of MySQL Connector/J from [the documentation of MySQL Connector/J](https://dev.mysql.com/doc/connector-j/en/). From c976becbf1d36d5bb348d9a9068b004da957a109 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Wed, 5 Nov 2025 15:58:52 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Grace Cai --- develop/dev-guide-sample-application-java-jdbc.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/develop/dev-guide-sample-application-java-jdbc.md b/develop/dev-guide-sample-application-java-jdbc.md index 108e3a0f47f23..e9376409062a5 100644 --- a/develop/dev-guide-sample-application-java-jdbc.md +++ b/develop/dev-guide-sample-application-java-jdbc.md @@ -284,14 +284,14 @@ Unless you need to write complex SQL statements, it is recommended to use [ORM]( ### MySQL compatibility -When you insert data into a `DECIMAL` column, if the number of decimal places exceeds the defined scale, MySQL performs a `TRUNCATE` operation and inserts the data successfully, regardless of how many extra decimal places there are. +In MySQL, when you insert data into a `DECIMAL` column, if the number of decimal places exceeds the column's defined scale, MySQL automatically truncates the extra digits and inserts the truncated data successfully, regardless of how many extra decimal places there are. In TiDB v8.5.3 and earlier versions: -- If the number of decimal places exceeds the column's defined scale but does not exceed 72, TiDB also performs a `TRUNCATE` operation and inserts the data successfully. -- However, if the number of decimal places exceeds 72, the write operation fails and returns an error. +- If the number of decimal places exceeds the defined scale but does not exceed 72, TiDB also automatically truncates the extra digits and inserts the truncated data successfully. +- However, if the number of decimal places exceeds 72, the insertion fails and returns an error. -Starting from TiDB v8.5.4, TiDB's behavior aligns with that of MySQL: regardless of the number of excess decimal places, it performs a `TRUNCATE` operation and inserts the data successfully. +Starting from TiDB v8.5.4, TiDB aligns its behavior with MySQL: regardless of how many extra decimal places there are, it automatically truncates the extra digits and inserts the truncated data successfully. ## Next steps