Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The result of comparison function on date value should return DATE type #46475

Closed
pcqz opened this issue Aug 29, 2023 · 3 comments · Fixed by #48032
Closed

The result of comparison function on date value should return DATE type #46475

pcqz opened this issue Aug 29, 2023 · 3 comments · Fixed by #48032
Labels
affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 component/expression found/gs found by gs report/customer Customers have encountered this bug. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug. type/compatibility

Comments

@pcqz
Copy link

pcqz commented Aug 29, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

bash$ mysql --column-type-info

mysql> select coalesce(current_date(),null) from dual;

2. What did you expect to see? (Required)

Field   1:  `coalesce(current_date(),null)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       DATE
...

3. What did you see instead (Required)

Field   1:  `coalesce(current_date(),null)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       DATETIME
...

4. What is your TiDB version? (Required)

v6.6.0

@pcqz pcqz added the type/bug The issue is confirmed as a bug. label Aug 29, 2023
@dveeden
Copy link
Contributor

dveeden commented Aug 29, 2023

This causes issues with MySQL Connector/J 8.x

package com.pingcap.tidb_demo_java;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;

public class App 
{
    public static void main( String[] args )
    {
	try {
		Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
	} catch (Exception ex) {
		System.out.println("Failed to load driver: " + ex.getMessage());
	}

	try {
		Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:4000?user=root");

		// This works
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT CURRENT_DATE()");
		rs.next();
		System.out.println("CURRENT_DATE() result: " + rs.getString("CURRENT_DATE()"));

		// This results in SQLException: Invalid length (10) for type TIMESTAMP
		// Tested on TiDB v7.3.0
		Statement stmt2 = conn.createStatement();
		ResultSet rs2 = stmt.executeQuery("SELECT COALESCE(CURRENT_DATE(),NULL) a");
		rs2.next();
		System.out.println("CURRENT_TIMESTAMP() result: " + rs2.getString("a"));
	} catch (SQLException ex) {
		System.out.println("SQLException: " + ex.getMessage());
	}

    }
}

Output:

$ java -cp /usr/share/java/mysql-connector-j.jar:target/tidb_demo_java-1.0-SNAPSHOT.jar com.pingcap.tidb_demo_java.App
CURRENT_DATE() result: 2023-08-29
SQLException: Invalid length (10) for type TIMESTAMP

@ti-chi-bot ti-chi-bot bot added may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Aug 29, 2023
@dveeden dveeden added affects-7.1 affects-6.5 affects-6.1 affects-5.4 This bug affects 5.4.x versions. affects-5.3 This bug affects 5.3.x versions. component/expression and removed may-affects-7.1 may-affects-6.5 may-affects-6.1 may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. labels Aug 29, 2023
@jebter jebter added the sig/execution SIG execution label Sep 4, 2023
@seiya-annie
Copy link

/found gs

@yibin87
Copy link
Contributor

yibin87 commented Sep 10, 2024

/report customer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 component/expression found/gs found by gs report/customer Customers have encountered this bug. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug. type/compatibility
Projects
None yet
6 participants