- 
                Notifications
    You must be signed in to change notification settings 
- Fork 11.6k
[Pull Request] Support for double data type in schema builder. #2094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| +1 for this. thanks. | 
| +1 for this | 
| Thanks all! I should add that there is also double support for all four databases laravel supports. MySQL is just the only one of the four that supports the extended syntax. Use the extended syntax using another connector and it will be ignored, just like it does with $table->float('col', 5, 2). | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a space in between the = signs and the default values. Also why not use the same default values as float?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add those spaces in. As for the default values, I thought I made my reasoning for the use of null clear in my original post in this pull request, but I'll try to be more explicit here.
The only reason, as far as I can tell, the last two parameters exist in float() is MySQL. The other database grammars ignore the specified $total and $places. If you look at the examples I gave in the first post (reproduced below) you'll see that the SQL generated for MySQL is different based on whether $total and $places are set explicitly or the default values are used. If the defaults were the same as float, you would have to use $table->double('col', null, null) to get the default syntax without the extra parameters, which is a confusing syntax.
With your permission, I'd like to change the default parameters for float in the same way. Also, can you tell me why float()'s default values are 8 and 2? It seems rather arbitrary to me.
Standard SQL DOUBLE syntax in MySQL is:
$table->double('double_col_1');Which is translated into:
alter table `table` add `double_col_1` double not nullAnd the nonstandard MySQL DOUBLE syntax option expressed as:
$table->double('double_col_2', 15, 8);Which is translated into:
alter table `table` add `double_col_2` double(15, 8) not null
| @taylorotwell Spaces have been added. See my comment in response to yours on the outdated diff for my response. | 
| Any comments on this? It's been a while... | 
| I'd like to see this included. | 
| Done on 4.0 branch and fixed the various issues. | 
| Just wanted to note I didn't quite feel right with the way I handled this pull request. Since it was to the wrong branch. I just fixed a few things and moved the code to the right branch. Since I work on this project in my spare time and I wanted to just get the issue done I chose to just move the code over. I'm not really comfortable with that decision and wanted to "make it right" so merging this pull request into master now. Thanks for your contribution! | 
I've implemented the feature discussed in issue #1955. This patch extends the Schema Builder syntax to include double support for columns. This means the following syntax is possible:
You'll notice there are two different ways to declare a double, with a specified precision or without. In addition to the simple double syntax, MySQL supports a second, nonstandard syntax.
From MySQL documentation:
Both of these syntaxes are supported in this patch, as you'll see in the examples below. It is important to support both syntaxes because documentation for the default
M,Din the extended syntax is surprisingly nonspecific, and those of use working on systems that already make use of the standard syntax might lose precision migrating to the extendedM,Dnotation.Examples
Standard SQL DOUBLE syntax in MySQL is:
Which is translated into:
And the nonstandard MySQL DOUBLE syntax option expressed as:
Which is translated into: