Skip to main content

TIME

In WormSQL, the TIME data type is used to store time values in the format 'HH:MM:SS.SSS'. The code snippet provided demonstrates how to create a table with TIME columns, insert data into it, and perform various queries and operations on the data.

Querying data from a table with TIME columns

To query data from a table with TIME columns, use the SELECT statement:

SELECT id, time1, time2 FROM TimeLog;

Filtering data using TIME columns

You can use various comparison operators like >, <, <=, >=, and = to filter data based on TIME columns:

SELECT * FROM TimeLog WHERE time1 > time2;

SELECT * FROM TimeLog WHERE time1 <= time2;

SELECT * FROM TimeLog WHERE time1 = TIME '14:59:00';

SELECT * FROM TimeLog WHERE time1 < '1:00 PM';

Performing time arithmetic

You can perform arithmetic operations on TIME columns using INTERVAL:

SELECT
id,
time1 - time2 AS time_sub,
time1 + INTERVAL '1' HOUR AS add,
time2 - INTERVAL '250' MINUTE AS sub
FROM TimeLog;

You can also add a TIME column to a DATE value to get a TIMESTAMP result:

SELECT
id,
DATE '2021-01-05' + time2 AS timestamp
FROM TimeLog LIMIT 1;

Handling invalid time values

If you try to insert an invalid time value into a TIME column, WormSQL will return an error:

INSERT INTO TimeLog VALUES (1, '12345-678', '20:05:01');

This will result in an error similar to the following:

failed to parse time 12345-678

Conclusion

In WormSQL, the TIME data type is used to store time values in the format 'HH:MM:SS.SSS'. The provided code snippet demonstrates how to create a table with TIME columns, insert data into it, and perform various queries and operations on the data. WormSQL supports arithmetic operations on TIME columns using INTERVAL, and you can also add a TIME column to a DATE value to get a TIMESTAMP result. Keep in mind that inserting invalid time values into a TIME column will result in an error.