How to insert integer as default value?

darkangel's profile image darkangel posted 15 years ago in General Permalink
Hi,

I can't see an option to insert an integer as a default value in the table editor, only Text, NULL, CURRENT_TIMESTAMP, ON UPDATE CURRENT_TIMESTAMP, and AUTO_INCREMENT.

?

_da.
ansgar's profile image ansgar posted 15 years ago Permalink
Yes, you have to put numbers with the text option.

The reason for why numbers get treated as text here is that a SHOW CREATE TABLE also returns numbers as quoted strings. No chance to detect numeric values as such. However, a cosmetic problem, as the server will deny your ALTER statement if it contains an invalid default value.
darkangel's profile image darkangel posted 15 years ago Permalink

Yes, you have to put numbers with the text option.

The reason for why numbers get treated as text here is that a SHOW CREATE TABLE also returns numbers as quoted strings. No chance to detect numeric values as such. However, a cosmetic problem, as the server will deny your ALTER statement if it contains an invalid default value.


You know the data type of the column is numeric, so you could use that information to generate an unquoted value.

Then change "Text:" to "Value:" or whatever where you input the default value.

Just a thought.

_da.
ansgar's profile image ansgar posted 15 years ago Permalink
Unquoting numbers in the ALTER or CREATE code wouldn't make an effective difference, so that's why this issue is rather cosmetic. But changing the label to "Custom value" or whatever is a good idea, would make it clear that there can also be numbers.
darkangel's profile image darkangel posted 15 years ago Permalink
OK.
darkangel's profile image darkangel posted 15 years ago Permalink
Anse,

The issue is when you don't wish to specify a default value (you want to use the implicit default value for the column data type). Then you get CREATE code like this:

CREATE TABLE `my_table` (
`Column 1` INT(10) NOT NULL DEFAULT ''
)

... which gives you an error. You need to be able to specify a default value of "None" (which should probably be positioned before all other options).

Also, if an existing table has fields without explicit defaults, the CREATE code incorrectly shows a default value of '' (empty string) for integer types (it shouldn't show any default value – for other data types as well). On more than one occasion I've sent CREATE code to a friend and he's been like "WTF?".

Thanks,

_da (Glen).
darkangel's profile image darkangel posted 15 years ago Permalink
Just noticed issue #1261. :)
ansgar's profile image ansgar posted 15 years ago Permalink
Thanks!

Please login to leave a reply, or register at first.