Bug #51632 Date type column problem when using UNION
Submitted: 2 Mar 2010 10:04 Modified: 2 Apr 2010 10:14
Reporter: Michael Garcia Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.77 OS:Linux (CentOS 5.2)
Assigned to: CPU Architecture:Any
Tags: timestamp, UNION

[2 Mar 2010 10:04] Michael Garcia
Description:
when trying to add totals row to selected records via UNION, the timestamp column seems to change type, because in the result retrieved via PHP the relevant timestamp column gets truncated to first 3 symbols.
this is definitely not PHP problem.

How to repeat:
#create table:
CREATE TABLE `table1` (
`price`  double NULL ,
`dt` timestamp NOT NULL default '0000-00-00 00:00:00'
)
;

#mysql function //stored procedure
( select * from table where dt>'2000-01-01' order by dt
) UNION (
 select 
CASE WHEN SUM(price) IS NULL THEN  '-' ELSE FORMAT( SUM(price),2 ) END AS price
,''
 FROM table1 where dt>'2000-01-01'
);

#when used via php PDO, date values from union's 1st part get truncated like "01." instead of "01.01.2001"

#workaround:
using DATE_FORMAT(now(), '%d.%m.%Y') instead of '' in the 2nd part of the UNION.
[2 Mar 2010 10:14] Sveta Smirnova
Thank you for the report.

This can be PDO problem as well. Please try to run same query using mysql command line client and inform us if formatting still wrong.
[2 Apr 2010 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".