Skip to content

Commit cf20cc0

Browse files
committed
Add some test cases to improve test coverage of parse_expr.c.
I chanced to notice while thumbing through lcov reports that we had exactly no coverage of BETWEEN SYMMETRIC, nor of current_time(N) and localtime(N). Improve that. parse_expr.c still has a pretty awful coverage number, but a large part of that is due to lack of coverage of the operator_precedence_warning logic. I have zero desire to write tests for that; I think ripping it out would be more sensible at this point.
1 parent 79b9471 commit cf20cc0

File tree

2 files changed

+116
-2
lines changed

2 files changed

+116
-2
lines changed

src/test/regress/expected/expressions.out

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--
2-
-- expression evaluated tests that don't fit into a more specific file
2+
-- expression evaluation tests that don't fit into a more specific file
33
--
44
--
55
-- Tests for SQLVAlueFunction
@@ -18,12 +18,24 @@ SELECT now()::timetz::text = current_time::text;
1818
t
1919
(1 row)
2020

21+
SELECT now()::timetz(4)::text = current_time(4)::text;
22+
?column?
23+
----------
24+
t
25+
(1 row)
26+
2127
SELECT now()::time::text = localtime::text;
2228
?column?
2329
----------
2430
t
2531
(1 row)
2632

33+
SELECT now()::time(3)::text = localtime(3)::text;
34+
?column?
35+
----------
36+
t
37+
(1 row)
38+
2739
-- current_timestamp / localtimestamp (always matches because of transactional behaviour)
2840
SELECT current_timestamp = NOW();
2941
?column?
@@ -75,3 +87,74 @@ SELECT current_schema;
7587
(1 row)
7688

7789
RESET search_path;
90+
--
91+
-- Tests for BETWEEN
92+
--
93+
explain (costs off)
94+
select count(*) from date_tbl
95+
where f1 between '1997-01-01' and '1998-01-01';
96+
QUERY PLAN
97+
-----------------------------------------------------------------------------
98+
Aggregate
99+
-> Seq Scan on date_tbl
100+
Filter: ((f1 >= '01-01-1997'::date) AND (f1 <= '01-01-1998'::date))
101+
(3 rows)
102+
103+
select count(*) from date_tbl
104+
where f1 between '1997-01-01' and '1998-01-01';
105+
count
106+
-------
107+
3
108+
(1 row)
109+
110+
explain (costs off)
111+
select count(*) from date_tbl
112+
where f1 not between '1997-01-01' and '1998-01-01';
113+
QUERY PLAN
114+
--------------------------------------------------------------------------
115+
Aggregate
116+
-> Seq Scan on date_tbl
117+
Filter: ((f1 < '01-01-1997'::date) OR (f1 > '01-01-1998'::date))
118+
(3 rows)
119+
120+
select count(*) from date_tbl
121+
where f1 not between '1997-01-01' and '1998-01-01';
122+
count
123+
-------
124+
12
125+
(1 row)
126+
127+
explain (costs off)
128+
select count(*) from date_tbl
129+
where f1 between symmetric '1997-01-01' and '1998-01-01';
130+
QUERY PLAN
131+
----------------------------------------------------------------------------------------------------------------------------------------------
132+
Aggregate
133+
-> Seq Scan on date_tbl
134+
Filter: (((f1 >= '01-01-1997'::date) AND (f1 <= '01-01-1998'::date)) OR ((f1 >= '01-01-1998'::date) AND (f1 <= '01-01-1997'::date)))
135+
(3 rows)
136+
137+
select count(*) from date_tbl
138+
where f1 between symmetric '1997-01-01' and '1998-01-01';
139+
count
140+
-------
141+
3
142+
(1 row)
143+
144+
explain (costs off)
145+
select count(*) from date_tbl
146+
where f1 not between symmetric '1997-01-01' and '1998-01-01';
147+
QUERY PLAN
148+
-----------------------------------------------------------------------------------------------------------------------------------------
149+
Aggregate
150+
-> Seq Scan on date_tbl
151+
Filter: (((f1 < '01-01-1997'::date) OR (f1 > '01-01-1998'::date)) AND ((f1 < '01-01-1998'::date) OR (f1 > '01-01-1997'::date)))
152+
(3 rows)
153+
154+
select count(*) from date_tbl
155+
where f1 not between symmetric '1997-01-01' and '1998-01-01';
156+
count
157+
-------
158+
12
159+
(1 row)
160+

src/test/regress/sql/expressions.sql

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--
2-
-- expression evaluated tests that don't fit into a more specific file
2+
-- expression evaluation tests that don't fit into a more specific file
33
--
44

55
--
@@ -13,7 +13,9 @@ SELECT date(now())::text = current_date::text;
1313

1414
-- current_time / localtime
1515
SELECT now()::timetz::text = current_time::text;
16+
SELECT now()::timetz(4)::text = current_time(4)::text;
1617
SELECT now()::time::text = localtime::text;
18+
SELECT now()::time(3)::text = localtime(3)::text;
1719

1820
-- current_timestamp / localtimestamp (always matches because of transactional behaviour)
1921
SELECT current_timestamp = NOW();
@@ -34,3 +36,32 @@ SELECT current_schema;
3436
SET search_path = 'pg_catalog';
3537
SELECT current_schema;
3638
RESET search_path;
39+
40+
41+
--
42+
-- Tests for BETWEEN
43+
--
44+
45+
explain (costs off)
46+
select count(*) from date_tbl
47+
where f1 between '1997-01-01' and '1998-01-01';
48+
select count(*) from date_tbl
49+
where f1 between '1997-01-01' and '1998-01-01';
50+
51+
explain (costs off)
52+
select count(*) from date_tbl
53+
where f1 not between '1997-01-01' and '1998-01-01';
54+
select count(*) from date_tbl
55+
where f1 not between '1997-01-01' and '1998-01-01';
56+
57+
explain (costs off)
58+
select count(*) from date_tbl
59+
where f1 between symmetric '1997-01-01' and '1998-01-01';
60+
select count(*) from date_tbl
61+
where f1 between symmetric '1997-01-01' and '1998-01-01';
62+
63+
explain (costs off)
64+
select count(*) from date_tbl
65+
where f1 not between symmetric '1997-01-01' and '1998-01-01';
66+
select count(*) from date_tbl
67+
where f1 not between symmetric '1997-01-01' and '1998-01-01';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy