Skip to content

Use decimal data type for the TRUNCATE argument to address the Truncated incorrect INTEGER value: '' warning#21712

Open
qiancai wants to merge 2 commits into
pingcap:masterfrom
qiancai:use_decimal_as_truncate_argument-18561
Open

Use decimal data type for the TRUNCATE argument to address the Truncated incorrect INTEGER value: '' warning#21712
qiancai wants to merge 2 commits into
pingcap:masterfrom
qiancai:use_decimal_as_truncate_argument-18561

Conversation

@qiancai

@qiancai qiancai commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

What is changed, added or deleted? (Required)

This pull request replaces the data type for the truncate argument from varchar to decimal because the current example raises the Truncated incorrect INTEGER value: '' warning.

  • Current example that raises the Truncated incorrect INTEGER value: '' warning.
mysql> use test;
Database changed
mysql> create table t(id int primary key, a varchar(10) not null);
Query OK, 0 rows affected (0.07 sec)

mysql> desc select * from t where truncate(a, " ") = '1';
+-------------------------+----------+-----------+---------------+---------------------------------------------------+
| id                      | estRows  | task      | access object | operator info                                     |
+-------------------------+----------+-----------+---------------+---------------------------------------------------+
| Selection_5             | 8000.00  | root      |               | eq(truncate(cast(test.t.a, double BINARY), 0), 1) |
| └─TableReader_7         | 10000.00 | root      |               | data:TableFullScan_6                              |
|   └─TableFullScan_6     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                    |
+-------------------------+----------+-----------+---------------+---------------------------------------------------+
3 rows in set, 2 warnings (0.00 sec)

mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                      |
+---------+------+------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: ''                                                                                        |
| Warning | 1105 | Scalar function 'truncate'(signature: TruncateReal, return type: double) is not supported to push down to storage layer now. |
+---------+------+------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>
mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v8.1.0
Edition: Community
Git Commit Hash: 945d07c5d5c7a1ae212f6013adfb187f2de24b23
Git Branch: HEAD
UTC Build Time: 2024-05-21 03:52:40
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

mysql>
  • Updated example that does not raise the Truncated incorrect INTEGER value: '' warning.
mysql> drop table t;
Query OK, 0 rows affected (0.19 sec)

mysql> create table t(id int primary key, a decimal(10, 2) not null);
Query OK, 0 rows affected (0.07 sec)

mysql> desc select * from t where truncate(a, 0) = 1;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| Selection_5             | 8000.00  | root      |               | eq(truncate(test.t.a, 0), 1)   |
| └─TableReader_7         | 10000.00 | root      |               | data:TableFullScan_6           |
|   └─TableFullScan_6     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                               |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1105 | Scalar function 'truncate'(signature: TruncateDecimal, return type: decimal(8,0)) is not supported to push down to storage layer now. |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v8.3 (TiDB 8.3 versions)
  • v8.2 (TiDB 8.2 versions)
  • v8.1 (TiDB 8.1 versions)
  • v8.0 (TiDB 8.0 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)
  • v5.3 (TiDB 5.3 versions)
  • v5.2 (TiDB 5.2 versions)

What is the related PR or file link(s)?

This document says "Truncate to specified number of decimal places".
https://docs.pingcap.com/tidb/stable/numeric-functions-and-operators

TRUNCATE() Truncate to specified number of decimal places

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

@qiancai qiancai added translation/from-docs This PR is translated from a PR in pingcap/docs. type/bugfix This PR fixes a bug. labels Jun 11, 2026
@ti-chi-bot ti-chi-bot Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 11, 2026
Synced from: pingcap/docs#18561
Target PR: pingcap#21712
AI Provider: azure

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Auto-sync completed successfully

Source PR: pingcap/docs#18561
Target PR: #21712

Chinese documentation has been updated based on English documentation changes.

@ti-chi-bot ti-chi-bot Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 11, 2026
@qiancai

qiancai commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

/approve

@qiancai qiancai added the lgtm label Jun 12, 2026
@qiancai qiancai self-assigned this Jun 12, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiancai

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the approved label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm size/S Denotes a PR that changes 10-29 lines, ignoring generated files. translation/from-docs This PR is translated from a PR in pingcap/docs. type/bugfix This PR fixes a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant