Home > OS >  How to insert output of strftime?
How to insert output of strftime?

Time:09-28

I want to insert the output of the strftime in the column Day_name. It doesn't show any error message but it didn't insert anything:

INSERT INTO reviews(Day_name)SELECT strftime('%w', pub_date) FROM reviews;

CodePudding user response:

You are trying to add to the table a number of records which is the result of a SELECT from the same table. If the table is empty, the SELECT will return no rows, and you will be adding nothing. On the other hand, if reviews had one hundred records, you would end up adding one hundred more. If you want to insert a single value:

INSERT INTO reviews(Day_name) SELECT strftime('%w', pub_date);

EDIT: Since what you really want is to UPDATE existing rows, then you should use the UPDATE command:

UPDATE reviews SET Day_name = strftime('%w', pub_date);

This syntax will update every row of the table.

  • Related