List:General Discussion« Previous MessageNext Message »
From:Gleb Paharenko Date:October 18 2005 5:03pm
Subject:Re: ALTER TABLE - how to fix truncated data?
View as plain text  
Hello.

> 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 |
+---------+------+-----------------------------------------------------+

mysql> select version();
+---------------------+
| version()           |
+---------------------+
| 5.0.13-rc-debug-log |
+---------------------+



Martijn Tonies wrote:
> 
> As a sidenote - shouldn't MySQL raise an error when data gets truncated?
> 
> If the truncation happens silently, chances are you'll never find out until
> someone does a report or whatever?!
> 
> 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
> 
> 


-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Gleb Paharenko
 / /|_/ / // /\ \/ /_/ / /__   Gleb.Paharenko@stripped
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.NET
       <___/   www.mysql.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