Time Series Analysis in PostgreSQL
Jasmin Ludolf
Content Developer, DataCamp
In PostgreSQL:
DATE
: date data onlyTIME
: time information without time zoneTIMESTAMP
: combines date and time without time zoneTIMESTAMPTZ
: TIMESTAMP
with time zonesINTERVAL
: time between two pointsDATE
: YYYY-MM-DD (ISO 8601 international standard)TIME
: HH:MM:SS (seconds can be decimals, 12 or 24 hour clock)TIMESTAMP
: YYYY-MM-DD HH:MM:SSTIMESTAMPTZ
: YYYY-MM-DD HH:MM:SS+/-HH (+01:00 or CET)INTERVAL
: one input example is 1 02:30:04CREATE TABLE timetable ( date_info DATE,
time_info TIMESTAMP,
time_with_zone TIMESTAMPTZ,
interval_length INTERVAL);
INSERT INTO timetable( date_info,
time_info,
time_with_zone,
interval_length)
VALUES ( 'January 23 2013',
'2023-01-20 18:00:00',
'2023-01-20 18:00:00 EST',
'1 02:03:04');
SELECT *
FROM timetable;
| date_info | time_info | time_with_zone | interval_length |
| ---------- | ------------------- | ------------------------- | --------------- |
| 2023-01-20 | 2023-01-20 18:00:00 | 2023-01-20 00:00:00+01:00 | 1 day, 2:03:04 |
INSERT INTO timetable(time_info)
VALUES ('2020-02-20 12:00:00');
SELECT *
FROM timetable;
| date_info | time_info | time_with_zone | interval_length |
| ---------- | ------------------- | ------------------------- | --------------- |
| 2023-01-20 | 2023-01-20 18:00:00 | 2023-01-20 00:00:00+01:00 | 1 day, 2:03:04 |
| null. | 2020-02-20 12:00:00 | null | null |
INSERT INTO timetable(time_info)
VALUES ('2020-02-20 02:00:00 EST');
SELECT *
FROM timetable;
| date_info | time_info | time_with_zone | interval_length |
| ---------- | ------------------- | ------------------------- | --------------- |
| 2023-01-20 | 2023-01-20 18:00:00 | 2023-01-20 00:00:00+01:00 | 1 day, 2:03:04 |
| null. | 2020-02-20 02:00:00 | null | null |
|unix_time |
|----------|
|1483444800|
That's January 3 2017!
Time Series Analysis in PostgreSQL