-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Support expressions (functions) for field defaults (table definition), ALTER, INSERT, CREATE? #14371
Comments
Confirmed. Have a look to #15006, #14986 for data examples CREATE TABLE issue_default_values (
logtime01 varchar(40) NOT NULL DEFAULT current_timestamp,
logtime0 datetime(2) NOT NULL DEFAULT current_timestamp,
logtime datetime(2) NOT NULL DEFAULT current_timestamp(2),
logtext varchar(255) NOT NULL DEFAULT current_timestamp(3),
logtext11 text NOT NULL DEFAULT current_timestamp(3),
uuid1 BINARY(16) DEFAULT unhex(replace(uuid(),'-','')),
uuid int(11) DEFAULT year(now() )
); |
Could this be fixed before 5.0? |
@OlafvdSpek If someone finds a fix (before end of this month) that supports all use cases, why not |
Why not block the release until it's fixed? |
@OlafvdSpek you can email @ibennetch or discuss it here or on #15607 🤷♂️ |
Ah, you mean whether to block or not. |
I will try to reproduce and fix this 👍 |
Yeah sure go ahead : ) |
Can anyone help me reproduce this I tried it in -> DEMO |
@yashrajbothra you need to use difficult examples |
This comment has been minimized.
This comment has been minimized.
@yashrajbothra did you try queries from the linked issues in my comment? |
Thanks @williamdes So,I looked into all the related issue and What i understood is that the when we insert any pre-defined functions of mysql into value it treats function as string.Execpt current_timestap() . So, current_timestap(2) is also treated as string. Did i get it Alright ? |
Yes you dit get it alright @yashrajbothra |
Who approved that condition? ;) |
@OlafvdSpek can you be more explicit? |
The first part is too hard to understand, |
@OlafvdSpek I think this de250fb commit . |
That would maybe be a solution but be sure that very custom non standard functions also work Basically I think we can say that the rule is : keep the user defined default value (function or mysql magic constants like timestamp) usable for insertion but also allow that the user changes the function or uses a hard coded value Thoes conditions make a fix very complicated IMO but a great idea could solve all the cases :) |
But if we keep functions in USER DEFINED DEFAULT VALUES how will we diffrentiate that the input is a function or string? @williamdes Did you mean to hard code all the mysql function like we did with current_timestamp() ? |
I have no idea it is a challenge to solve :) And no for hard coding the functions, I will not work because the possibilities are endless Maybe we could add an option the the selected function that would equal to the default value of the column |
No parameter is possible for a column that defines a function as default value ;) |
Like if CURDATE() doesnt expect a param. we should disable the value for the same. If i am correct than i will definetly include that 👍 |
I think I did not explain well my point The list will contain
Obviously it is impossible that it can have a parameter because the table schema will not allow that. So for that particular option I do not want that the user fills a value that will not be used anyway Just to say in another way: |
I this was able to understand your point 👍
but If in case lets say i have a table with a column without any default value. When i insert data from INSERT form i want to use USER_DEFINED function (which is not a default value). Can we do that as of now?. Or this is totally diffrent issue? |
;)
Yes, I would like to avoid mixing features :) |
2 years later and still not fixed... |
Reading thought this thread, I wonder if maybe an easier solution is to add the Ideally this The insert SQL with the option selected could then be e.g. For the alter CREATE/ALTER views would it be too naïve just to look for a leading That could be combined with a simple |
Thank you for the feedback, adding the DEFAULT function seems a good idea ! And adding a |
Isn't mapping empty to default enough for the insert form? |
If the empty function
For fields that don't have a DEFAULT value set you would have to treat these differently or |
Currently '' is used for 'empty' integers, which produces a warning. |
+1 Very glad seeing this in the 5.2.0 milestone! Thank you |
This is still not solved. I use Thus they are string columns, that have When I change the order of columns via phpMyAdmin, they would be wrapped with single, or multiple quotes, and the |
MariaDB 10.2 supports expressions for field defaults. However pMA escapes and quotes the expression, causing it to become an ordinary string.
https://mariadb.com/kb/en/library/create-table/#default
The text was updated successfully, but these errors were encountered: