It is necessary to add a column in which when adding a line the name of the current day of the week would be written. Tried with several types and set the default DAYNAME(CURDATE()) , did not work. Approximately as implemented here over time

 `add_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 
  • What for? Leave add_time DATETIME DEFAULT CURRENT_TIMESTAMP , and get the day of the week in the request using the function. - Akina
  • @Akina add_time remains. it is necessary to add a new field to the existing ones - cruim
  • This is called "overridden data" —when the stored value can be calculated based on other values. And in every way possible it is condemned, if there is no absolutely deadly justification. You - no, or at least not yet announced. Therefore, adding a day of the week field, although its value is easily considered in the request, is an erroneous decision. It is not too late - refuse. To avoid problems of data discrepancy in the future. - Akina
  • @Akina is a request that in a certain way receives data for the past week, certain calculations are made and displayed to the user. During the week, the indicators change. Data is saved every day. There is a need next to the calculated columns, to display columns with the difference between the current and "top" of the same day of the week. It seemed to me easier to do this by appending the day of the week to the line. Ready to listen to comments and suggestions. - cruim
  • Your explanation is evidence that the redefinition of data in your case is not justified. The proposal has already been announced - to receive the day of the week at the moment when its value is required. The expression in the query. - Akina

1 answer 1

Try a trigger:

 CREATE TRIGGER `trigger_name` BEFORE INSERT ON `table_name` FOR EACH ROW IF NEW.`field_name` IS NULL THEN SET NEW.`field_name` = DAYNAME(CURDATE()); END IF;