-
Notifications
You must be signed in to change notification settings - Fork 2
/
gps table with virtual column.sql
34 lines (33 loc) · 1.22 KB
/
gps table with virtual column.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
CREATE TABLE `gps` (
`id` bigint NOT NULL AUTO_INCREMENT,
`hostname` varchar(255) NOT NULL,
`record_timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`gps_timestamp` varchar(64) NOT NULL,
`class` varchar(10) NOT NULL,
`tag` varchar(255) NOT NULL,
`device` varchar(255) NOT NULL,
`mode` int NOT NULL,
`ept` float NOT NULL,
`lat` double NOT NULL,
`lon` double NOT NULL,
`alt` float NOT NULL,
`epx` float NOT NULL,
`epy` float NOT NULL,
`epv` float NOT NULL,
`track` float NOT NULL,
`speed` float NOT NULL,
`climb` float NOT NULL,
`epd` float NOT NULL,
`eps` float NOT NULL,
`epc` float NOT NULL,
`v_gps_timestamp` timestamp(6) GENERATED ALWAYS AS (
(case
when (locate(_utf8mb4'.',`gps_timestamp`) = 0) then convert_tz(str_to_date(`gps_timestamp`,_utf8mb4'%Y-%m-%dT%H:%i:%sZ'),_utf8mb4'Zulu',_utf8mb4'America/New_York')
when (locate(_utf8mb4'.',`gps_timestamp`) <> 0) then convert_tz(str_to_date(`gps_timestamp`,_utf8mb4'%Y-%m-%dT%H:%i:%s.%fZ'),_utf8mb4'Zulu',_utf8mb4'America/New_York')
end)
) VIRTUAL,
`cputemp` float DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `gps_record_timestamp_IDX` (`record_timestamp`) USING BTREE,
KEY `indx_v_gps_timestamp` (`v_gps_timestamp`)
)