Unix Technical Forum

Default Value 0 - rephrase

This is a discussion on Default Value 0 - rephrase within the MySQL forums, part of the Database Server Software category; --> Thanks to the people who answer me in my previous thread, I can now rephrase my problem : I ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:30 AM
Pierre Gilquin
 
Posts: n/a
Default Default Value 0 - rephrase

Thanks to the people who answer me in my previous thread, I can now rephrase
my problem :

I have a table A defined by :

create table A (
id bigint(9) NOT NULL ,
col bigint(9) NOT NULL ,
PRIMARY KEY (`id`)
)

if I insert a row with command : insert into a(id,col) values (1,null);
I get the correct exception :ERROR 1048: Column 'col' cannot be null

If I use the command : insert into a(id) values (1);
the row is create with value (1,0).

It seems to me that mysql is faulty for the second case. Do you agree with
me ?
What can I do for get rid of this default value and get an exception for
every command ?

Thanks in avance

Pierre



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:30 AM
lark
 
Posts: n/a
Default Re: Default Value 0 - rephrase

== Quote from Pierre Gilquin (inconnue@bluewin.ch)'s article
> Thanks to the people who answer me in my previous thread, I can now rephrase
> my problem :
> I have a table A defined by :
> create table A (
> id bigint(9) NOT NULL ,
> col bigint(9) NOT NULL ,
> PRIMARY KEY (`id`)
> )
> if I insert a row with command : insert into a(id,col) values (1,null);
> I get the correct exception :ERROR 1048: Column 'col' cannot be null
> If I use the command : insert into a(id) values (1);
> the row is create with value (1,0).
> It seems to me that mysql is faulty for the second case. Do you agree with
> me ?
> What can I do for get rid of this default value and get an exception for
> every command ?
> Thanks in avance
> Pierre


my suggestion is to create a trigger for this table for any insert and/or update
operations. good catch!

--
POST BY: lark with PHP News Reader ;o)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:30 AM
J.O. Aho
 
Posts: n/a
Default Re: Default Value 0 - rephrase

Pierre Gilquin wrote:

> create table A (
> id bigint(9) NOT NULL ,
> col bigint(9) NOT NULL ,
> PRIMARY KEY (`id`)
> )
> If I use the command : insert into a(id) values (1);
> the row is create with value (1,0).
> It seems to me that mysql is faulty for the second case. Do you agree with
> me ?


No, I can't agree with you. NULL != 0

NULL is "VOID", and ZERO is a value which is included in the INT and that
means you got a value all within the specification you gave when you created
the table.


> What can I do for get rid of this default value and get an exception for
> every command ?


Suggest you would use a function which then is used to insert the value to the
table.


--

//Aho
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:30 AM
Martijn Tonies
 
Posts: n/a
Default Re: Default Value 0 - rephrase


> Thanks to the people who answer me in my previous thread, I can now

rephrase
> my problem :
>
> I have a table A defined by :
>
> create table A (
> id bigint(9) NOT NULL ,
> col bigint(9) NOT NULL ,
> PRIMARY KEY (`id`)
> )
>
> if I insert a row with command : insert into a(id,col) values (1,null);
> I get the correct exception :ERROR 1048: Column 'col' cannot be null
>
> If I use the command : insert into a(id) values (1);
> the row is create with value (1,0).
>
> It seems to me that mysql is faulty for the second case. Do you agree with
> me ?


So, given that you don't have a DEFAULT clause, you're expecting
an exception? This is fair and one of the long annoying things with MySQL,
it just takes the "default" for the datatype when defined as NOT NULL.

> What can I do for get rid of this default value and get an exception for
> every command ?


You can get this exception if you use a different "sql mode", one that is
more strict. I believe MySQL 5 uses the more strict mode by default.

Check the documentation on sql mode, here's the reference for 5.1:
http://dev.mysql.com/doc/refman/5.1/...sql-modes.html

to get you an idea.


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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:30 AM
Martijn Tonies
 
Posts: n/a
Default Re: Default Value 0 - rephrase


> > create table A (
> > id bigint(9) NOT NULL ,
> > col bigint(9) NOT NULL ,
> > PRIMARY KEY (`id`)
> > )
> > If I use the command : insert into a(id) values (1);
> > the row is create with value (1,0).
> > It seems to me that mysql is faulty for the second case. Do you agree

with
> > me ?

>
> No, I can't agree with you. NULL != 0
>
> NULL is "VOID", and ZERO is a value which is included in the INT and that
> means you got a value all within the specification you gave when you

created
> the table.


Yes, except that the OP did NOT insert a 0, but MySQL "assumed" a default
of 0 because the column is defined as "not null".


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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:30 AM
Pierre Gilquin
 
Posts: n/a
Default Re: Default Value 0 - rephrase

Thanks for you useful suggestion.

Pierre

"Martijn Tonies" <m.tonies@upscene.removethis.com> a écrit dans le message
de news: 476a4779$0$26876$e4fe514c@dreader27.news.xs4all.nl ...
>
>> Thanks to the people who answer me in my previous thread, I can now

> rephrase
>> my problem :
>>
>> I have a table A defined by :
>>
>> create table A (
>> id bigint(9) NOT NULL ,
>> col bigint(9) NOT NULL ,
>> PRIMARY KEY (`id`)
>> )
>>
>> if I insert a row with command : insert into a(id,col) values (1,null);
>> I get the correct exception :ERROR 1048: Column 'col' cannot be null
>>
>> If I use the command : insert into a(id) values (1);
>> the row is create with value (1,0).
>>
>> It seems to me that mysql is faulty for the second case. Do you agree
>> with
>> me ?

>
> So, given that you don't have a DEFAULT clause, you're expecting
> an exception? This is fair and one of the long annoying things with MySQL,
> it just takes the "default" for the datatype when defined as NOT NULL.
>
>> What can I do for get rid of this default value and get an exception for
>> every command ?

>
> You can get this exception if you use a different "sql mode", one that is
> more strict. I believe MySQL 5 uses the more strict mode by default.
>
> Check the documentation on sql mode, here's the reference for 5.1:
> http://dev.mysql.com/doc/refman/5.1/...sql-modes.html
>
> to get you an idea.
>
>
> --
> Martijn Tonies
> Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle
> &
> MS SQL Server
> Upscene Productions
> http://www.upscene.com
> My thoughts:
> http://blog.upscene.com/martijn/
> Database development questions? Check the forum!
> http://www.databasedevelopmentforum.com
>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:46 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com