From 2de2a1430e4e2342185a4868f01b60849b5c1435 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 2de789c41ac10..57467dd9e1c63 100644 --- a/develop/dev-guide-sample-application-java-jdbc.md +++ b/develop/dev-guide-sample-application-java-jdbc.md @@ -310,6 +310,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 4461034a1dd01f16e653be5bc5019315afa7d61f 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 57467dd9e1c63..9e4f66f36b89f 100644 --- a/develop/dev-guide-sample-application-java-jdbc.md +++ b/develop/dev-guide-sample-application-java-jdbc.md @@ -312,14 +312,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