Bug #10024 Only first character of column shown
Submitted: 20 Apr 2005 8:43 Modified: 13 Jul 2005 11:34
Reporter: Taco van den Broek Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.4-beta OS:Any (*)
Assigned to: Alexey Botchkov CPU Architecture:Any

[20 Apr 2005 8:43] Taco van den Broek
Description:
When selecting from two tables, using an inner join and order clause. A column created by an if statement and the from_unixtime function will only show its first character.

How to repeat:
Create tables foo and bar:
CREATE TABLE `bar` (
  `bar_id` int(11) NOT NULL auto_increment,
  `bar_title` varchar(30) NOT NULL,
  PRIMARY KEY  (`bar_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `foo` (
  `foo_id` int(11) NOT NULL auto_increment,
  `bar_id` int(11) NOT NULL,
  `unix_timestamp` int(11) default NULL,
  PRIMARY KEY  (`foo_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Insert data:
INSERT INTO foo VALUES (1,1,UNIX_TIMESTAMP('2005-04-05'));
INSERT INTO foo VALUES (2,2,UNIX_TIMESTAMP('2005-04-13'));
INSERT INTO bar VALUES (1,'baz');
INSERT INTO bar VALUES (2,'qux');

Two test queries, the first resultset will be as expected, the second will show only one character for the second column:
SELECT bar_title, IF(unix_timestamp IS NULL, '-', FROM_UNIXTIME(unix_timestamp, '%d-%m-%Y'))
FROM bar INNER JOIN foo ON foo.bar_id = bar.bar_id
ORDER BY foo_id asc;

SELECT bar_title, IF(unix_timestamp IS NULL, '-', FROM_UNIXTIME(unix_timestamp, '%d-%m-%Y'))
FROM bar INNER JOIN foo ON foo.bar_id = bar.bar_id;
[20 Apr 2005 12:46] Geert Vanderkelen
Hi Taco,

I could reproduce this in 5.0.3 and 5.0.4. It works correct in 4.1.11.
It only happens when adding ORDER BY to the statement and when using a field in expr1 of the IF() function and combining strings with integer for expr2 and expr3.

Thanks for the report!

Here couple of examples:
mysql-5.0.4-beta-standard-log> SELECT bar_title, IF(unix_timestamp IS NULL, 0, 546464) FROM bar LEFT JOIN foo ON foo.bar_id = bar.bar_id order by foo_id asc;
+-----------+---------------------------------------+
| bar_title | IF(unix_timestamp IS NULL, 0, 546464) |
+-----------+---------------------------------------+
| baz       |                                546464 |
| qux       |                                546464 |
+-----------+---------------------------------------+

mysql-5.0.4-beta-standard-log> SELECT bar_title, IF(unix_timestamp IS NULL, '-', 546464) FROM bar LEFT JOIN foo ON foo.bar_id = bar.bar_id order by foo_id asc;
+-----------+-----------------------------------------+
| bar_title | IF(unix_timestamp IS NULL, '-', 546464) |
+-----------+-----------------------------------------+
| baz       | 5                                       |
| qux       | 5                                       |
+-----------+-----------------------------------------+

mysql-5.0.4-beta-standard-log> SELECT bar_title, IF(unix_timestamp IS NULL, '-', unix_timestamp) FROM bar LEFT JOIN foo ON foo.bar_id = bar.bar_id order by foo_id asc;
+-----------+-------------------------------------------------+
| bar_title | IF(unix_timestamp IS NULL, '-', unix_timestamp) |
+-----------+-------------------------------------------------+
| baz       | 1                                               |
| qux       | 1                                               |
+-----------+-------------------------------------------------+

mysql-5.0.4-beta-standard-log> SELECT bar_title, IF(unix_timestamp IS NULL, '-', unix_timestamp) FROM bar LEFT JOIN foo ON foo.bar_id = bar.bar_id
    -> ;
+-----------+-------------------------------------------------+
| bar_title | IF(unix_timestamp IS NULL, '-', unix_timestamp) |
+-----------+-------------------------------------------------+
| baz       | 1112652000                                      |
| qux       | 1113343200                                      |
+-----------+-------------------------------------------------+

Best regards,

Geert
[13 Jul 2005 11:34] Alexey Botchkov
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Fixed with previous patches