Skip to content
Advertisement

INSERT INTO SELECT with CURRENT_TIMESTAMP value

I have a query that takes all data from database A and inserts it into database B. It is working correctly, however I created a new column in database B called “actual_date” and I would like that, when inserting the data in database B, also insert the current date when these values ​​were entered in database B.

Something like:

INSERT INTO databaseB(col1, col2, actual_date) SELECT databaseA.col1, databaseA.col2, CURRENT_TIMESTAMP FROM databaseA

Obviously the above query is wrong, but it would be something like this, because in database A, there is no column with the current date.

Is this possible?

Advertisement

Answer

Use Date():

INSERT INTO 
    databaseB (col1, col2, actual_date) 
SELECT 
    databaseA.col1, databaseA.col2, Date() 
FROM 
    databaseA
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement