Abhi Abhi - 6 months ago 27
SQL Question

Insert timestamp into table

We are working on MemSQL database and I want to insert time-series data into a table. MemSQL uses MySQL flavour as a query language to query database. I am using standard MySQL functions, Date_sub() which is running into an error message:

create table simpletest (edate timestamp, name varchar(20));

insert into simpletest values ("DATE_SUB(NOW(),INTERVAL 1 HOUR)", 'hi');


Should I be using a different function to insert data for last hour.

Answer

MemSQL doesn't support arbitrary expressions inside of insert statements as of MemSQL v5 (only literal constants). This limitation will be removed in the next release.

The best workaround is to write the query as an insert .. select instead:

INSERT INTO simpletest SELECT DATE_SUB(NOW(),INTERVAL 1 HOUR), 'hi';