1+ from tests .aggregate_tests .aggtst_base import TstView
2+
3+
4+ class arithtst_timestamp_minus_timestamp (TstView ):
5+ def __init__ (self ):
6+ # Result validation is not required for local views
7+ self .data = []
8+ self .sql = """CREATE LOCAL VIEW timestamp_minus_timestamp AS SELECT
9+ id,
10+ (c1-c2)SECOND AS c1_minus_c2
11+ FROM timestamp_tbl"""
12+
13+
14+ class arithtst_timestamp_minus_timestamp_seconds (TstView ):
15+ def __init__ (self ):
16+ # Validated on Postgres
17+ self .data = [
18+ {'id' : 0 , 'c1_minus_c2_seconds' : 160342920 },
19+ {'id' : 1 , 'c1_minus_c2_seconds' : - 84686400 },
20+ {'id' : 2 , 'c1_minus_c2_seconds' : 332907420 }
21+ ]
22+ self .sql = """CREATE MATERIALIZED VIEW timestamp_minus_timestamp_seconds AS SELECT
23+ id,
24+ CAST((c1_minus_c2) AS BIGINT) AS c1_minus_c2_seconds
25+ FROM timestamp_minus_timestamp"""
26+
27+
28+ # Equivalent SQL for Postgres
29+ # CREATE TABLE timestamp_minus_timestamp AS
30+ # SELECT
31+ # id,
32+ # c1 - c2 AS c1_minus_c2_days
33+ # FROM timestamp_tbl;
34+ #
35+ # SELECT
36+ # id,
37+ # EXTRACT(EPOCH FROM c1_minus_c2_days) AS c1_minus_c2_seconds
38+ # FROM timestamp_minus_timestamp ;
39+
40+
41+ class arithtst_timestamp_minus_interval (TstView ):
42+ def __init__ (self ):
43+ # Validated on Postgres
44+ self .data = [
45+ {'id' : 0 , 'c1' : '2019-11-05T08:27:00' , 'c2' : '2013-11-05T12:45:00' },
46+ {'id' : 1 , 'c1' : '2020-05-22T14:00:00' , 'c2' : '2022-02-26T18:00:00' },
47+ {'id' : 2 , 'c1' : '1959-05-22T11:32:00' , 'c2' : '1947-12-03T09:15:00' }
48+ ]
49+ self .sql = """CREATE MATERIALIZED VIEW timestamp_minus_interval AS SELECT
50+ id,
51+ c1 - INTERVAL '2592000' SECOND AS c1,
52+ c2 - INTERVAL '31536000' SECOND AS c2
53+ FROM timestamp_tbl"""
54+
55+
56+ class arithtst_timestamp_plus_interval (TstView ):
57+ def __init__ (self ):
58+ # Validated on Postgres
59+ self .data = [
60+ {'id' : 0 , 'c1' : '2020-01-04T08:27:00' , 'c2' : '2015-11-05T12:45:00' },
61+ {'id' : 1 , 'c1' : '2020-07-21T14:00:00' , 'c2' : '2024-02-26T18:00:00' },
62+ {'id' : 2 , 'c1' : '1959-07-21T11:32:00' , 'c2' : '1949-12-02T09:15:00' }
63+ ]
64+ self .sql = """CREATE MATERIALIZED VIEW timestamp_plus_interval AS SELECT
65+ id,
66+ c1 + INTERVAL '2592000' SECOND AS c1,
67+ c2 + INTERVAL '31536000' SECOND AS c2
68+ FROM timestamp_tbl"""
69+
70+
71+ # Equivalent SQL for Postgres
72+ # SELECT
73+ # (c1 + INTERVAL '2592000 second') AS c1,
74+ # (c2 + INTERVAL '31536000 second') AS c2
75+ # FROM timestamp_tbl;
0 commit comments