I want that when importing from csv to each record was added the field "adding time". I thought to do it in the same way as in a normal query and add a field to the field_createdAt table of type DATETIME , the default value of CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP . But when importing into these fields, they are written instead of the current date. Perhaps somehow solved?

  • what programming language? - L. Vadim
  • @ L.Vadim php. does it matter? I create a table in phpMyAdmin, with the appropriate columns and import the file there. - cruim
  • Upd. Filled the field "Name of columns" - all correctly writes. - cruim

2 answers 2

I thought to do it in the same way as in a normal query and add a field to the field_createdAt table of type DATETIME with the default CURRENT_TIMESTAMP attribute on update CURRENT_TIMESTAMP. But when importing into these fields, they are written instead of the current date.

When importing data, INSERT is performed, and not even UPDATE at all. So the field requires the attribute DEFAULT CURRENT_TIMESTAMP.

  • this attribute is assigned by default, right? created another column for the test, the attribute left blank. anyway zeros are written - cruim
  • So something is wrong. Probably importing without specifying the destination fields? Well then, specify the required value explicitly: LOAD DATA INFILE 'file.txt' INTO TABLE t1 (column1, column2) SET field_createdAt = CURRENT_TIMESTAMP; - Akina
  • I import to phpMyAdmin by simply specifying the csv file and choosing the CSV format using LOAD DATA. Where can I write the instructions that you specified? - cruim
  • I have no idea. I import only from the console or queries (which is basically the same thing). Try instead of import by means of pkhp-admin to write an import request and through php-admin to execute it, it should work as it should. - Akina

phpMyAdmin when creating a field defaulte expose "CURRENT_TIMESTAMP"

  • the point is that if you manually add something, then everything is fine, when importing from csv only zeros - cruim
  • Can you write what you are doing? with examples - L. Vadim
  • phpMyAdmin -> Import -> Select file -> I select -> Format -> CSV using LOAD DATA -> Forward. - cruim
  • the only thing I can offer is to import data from CSV using a small php script - L. Vadim