Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit165d581

Browse files
committed
Tighten handling of "ago" in interval values
This commit Restrict the unit "ago" to only appear at the end of theinterval. According to the documentation, a direction can only bedefined at the end of an interval, but it was possible to define it inthe middle of the string or define it multiple times.In spirit, this is similar to the error handling improvements done in5b3c595 orbcc704b.Author: Joseph KoshakowReviewed-by: Jacob Champion, Gurjeet Singh, Reid ThompsonDiscussion:https://postgr.es/m/CAAvxfHd-yNO+XYnUxL=GaNZ1n+eE0V-oE0+-cC1jdjdU0KS3iw@mail.gmail.com
1 parent9a0ddc3 commit165d581

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,6 +3578,13 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
35783578
break;
35793579

35803580
caseAGO:
3581+
3582+
/*
3583+
* "ago" is only allowed to appear at the end of the
3584+
* interval.
3585+
*/
3586+
if (i!=nf-1)
3587+
returnDTERR_BAD_FORMAT;
35813588
is_before= true;
35823589
type=uval;
35833590
break;

‎src/test/regress/expected/interval.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,3 +1787,12 @@ SELECT extract(epoch from interval '1000000000 days');
17871787
86400000000000.000000
17881788
(1 row)
17891789

1790+
-- "ago" can only appear once at the end of an interval.
1791+
SELECT INTERVAL '42 days 2 seconds ago ago';
1792+
ERROR: invalid input syntax for type interval: "42 days 2 seconds ago ago"
1793+
LINE 1: SELECT INTERVAL '42 days 2 seconds ago ago';
1794+
^
1795+
SELECT INTERVAL '2 minutes ago 5 days';
1796+
ERROR: invalid input syntax for type interval: "2 minutes ago 5 days"
1797+
LINE 1: SELECT INTERVAL '2 minutes ago 5 days';
1798+
^

‎src/test/regress/sql/interval.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,7 @@ SELECT f1,
582582

583583
-- internal overflow test case
584584
SELECT extract(epochfrom interval'1000000000 days');
585+
586+
-- "ago" can only appear once at the end of an interval.
587+
SELECT INTERVAL'42 days 2 seconds ago ago';
588+
SELECT INTERVAL'2 minutes ago 5 days';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp