List:General Discussion« Previous MessageNext Message »
From:Martijn Tonies Date:October 19 2005 6:04am
Subject:Re: ALTER TABLE - how to fix truncated data?
View as plain text  
Gleb,

> > As a sidenote - shouldn't MySQL raise an error when data gets
>truncated?
>
> MySQL raises a warning after such ALTER operation. See:
>
> mysql> create table dt(a decimal(4,1));
> Query OK, 0 rows affected (0.01 sec)
>
> mysql> insert into dt set a=999.1;
> Query OK, 1 row affected (0.00 sec)
>
> mysql> alter table dt change a a decimal(2,1);
> Query OK, 1 row affected, 1 warning (0.02 sec)
> Records: 1  Duplicates: 0  Warnings: 1
>
> mysql> show warnings;
> +---------+------+-----------------------------------------------------+
> | Level   | Code | Message                                             |
> +---------+------+-----------------------------------------------------+
> | Warning | 1264 | Out of range value adjusted for column 'a' at row 1 |
> +---------+------+-----------------------------------------------------+

Could be me ... but isn't this a little too late?

eg: AFTER you have lost your data?

IMO, it should raise an error UNLESS you force it to truncate the data.

With regards,

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS SQL
Server
Upscene Productions
http://www.upscene.com
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com

Thread
ALTER TABLE - how to fix truncated data?Jim Seymour17 Oct
  • Re: ALTER TABLE - how to fix truncated data?Gleb Paharenko18 Oct
  • Re: ALTER TABLE - how to fix truncated data?Martijn Tonies18 Oct
    • Re: ALTER TABLE - how to fix truncated data?Gleb Paharenko18 Oct
  • Re: ALTER TABLE - how to fix truncated data?Martijn Tonies19 Oct
  • Re: ALTER TABLE - how to fix truncated data?Harald Fuchs19 Oct
  • Re: ALTER TABLE - how to fix truncated data?Martijn Tonies19 Oct
    • Re: ALTER TABLE - how to fix truncated data?Jigal van Hemert19 Oct
    • Re: ALTER TABLE - how to fix truncated data?Gleb Paharenko19 Oct
  • Re: ALTER TABLE - how to fix truncated data?Martijn Tonies19 Oct