Skip to content

Commit 651d005

Browse files
committed
Revert use singular for -1 (commits 9ee7d53 and 5da9868
Turns out you can specify negative values using plurals: https://english.stackexchange.com/questions/9735/is-1-followed-by-a-singular-or-plural-noun so the previous code was correct enough, and consistent with other usage in our code. Also add comment in the two places where this could be confused. Reported-by: Noah Misch Diagnosed-by: 20210425115726.GA2353095@rfd.leadboat.com
1 parent e6f9539 commit 651d005

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

contrib/dblink/expected/dblink.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,9 @@ SELECT *
10991099
FROM dblink('myconn',
11001100
'SELECT * FROM (VALUES (''-1 2:03:04'')) i')
11011101
AS i(i interval);
1102-
i
1103-
------------------
1104-
-1 day -02:03:04
1102+
i
1103+
-------------------
1104+
-1 days -02:03:04
11051105
(1 row)
11061106

11071107
-- Try swapping to another format to ensure the GUCs are tracked

src/backend/utils/adt/datetime.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,7 +4190,7 @@ AddPostgresIntPart(char *cp, int value, const char *units,
41904190
(*is_before && value > 0) ? "+" : "",
41914191
value,
41924192
units,
4193-
(abs(value) != 1) ? "s" : "");
4193+
(value != 1) ? "s" : "");
41944194

41954195
/*
41964196
* Each nonzero field sets is_before for (only) the next one. This is a
@@ -4216,7 +4216,7 @@ AddVerboseIntPart(char *cp, int value, const char *units,
42164216
}
42174217
else if (*is_before)
42184218
value = -value;
4219-
sprintf(cp, " %d %s%s", value, units, (abs(value) == 1) ? "" : "s");
4219+
sprintf(cp, " %d %s%s", value, units, (value == 1) ? "" : "s");
42204220
*is_zero = false;
42214221
return cp + strlen(cp);
42224222
}
@@ -4414,6 +4414,7 @@ EncodeInterval(struct pg_tm *tm, fsec_t fsec, int style, char *str)
44144414
else if (is_before)
44154415
*cp++ = '-';
44164416
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, false);
4417+
/* We output "ago", not negatives, so use abs(). */
44174418
sprintf(cp, " sec%s",
44184419
(abs(sec) != 1 || fsec != 0) ? "s" : "");
44194420
is_zero = false;

src/interfaces/ecpg/pgtypeslib/interval.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ AddVerboseIntPart(char *cp, int value, const char *units,
694694
}
695695
else if (*is_before)
696696
value = -value;
697-
sprintf(cp, " %d %s%s", value, units, (abs(value) == 1) ? "" : "s");
697+
sprintf(cp, " %d %s%s", value, units, (value == 1) ? "" : "s");
698698
*is_zero = false;
699699
return cp + strlen(cp);
700700
}
@@ -711,7 +711,7 @@ AddPostgresIntPart(char *cp, int value, const char *units,
711711
(*is_before && value > 0) ? "+" : "",
712712
value,
713713
units,
714-
(abs(value) != 1) ? "s" : "");
714+
(value != 1) ? "s" : "");
715715

716716
/*
717717
* Each nonzero field sets is_before for (only) the next one. This is a
@@ -924,6 +924,7 @@ EncodeInterval(struct /* pg_ */ tm *tm, fsec_t fsec, int style, char *str)
924924
*cp++ = '-';
925925
AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, false);
926926
cp += strlen(cp);
927+
/* We output "ago", not negatives, so use abs(). */
927928
sprintf(cp, " sec%s",
928929
(abs(sec) != 1 || fsec != 0) ? "s" : "");
929930
is_zero = false;

src/interfaces/libpq/fe-print.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
303303
}
304304
if (po->header && !po->html3)
305305
fprintf(fout, "(%d row%s)\n\n", PQntuples(res),
306-
(abs(PQntuples(res)) == 1) ? "" : "s");
306+
(PQntuples(res) == 1) ? "" : "s");
307307
if (po->html3 && !po->expanded)
308308
fputs("</table>\n", fout);
309309
free(fieldMax);
@@ -662,7 +662,7 @@ PQdisplayTuples(const PGresult *res,
662662

663663
if (!quiet)
664664
fprintf(fp, "\nQuery returned %d row%s.\n", PQntuples(res),
665-
(abs(PQntuples(res)) == 1) ? "" : "s");
665+
(PQntuples(res) == 1) ? "" : "s");
666666

667667
fflush(fp);
668668

src/test/regress/expected/interval.out

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ SELECT INTERVAL '-08:00' AS "Eight hours";
2323
(1 row)
2424

2525
SELECT INTERVAL '-1 +02:03' AS "22 hours ago...";
26-
22 hours ago...
27-
------------------
28-
-1 day +02:03:00
26+
22 hours ago...
27+
-------------------
28+
-1 days +02:03:00
2929
(1 row)
3030

3131
SELECT INTERVAL '-1 days +02:03' AS "22 hours ago...";
32-
22 hours ago...
33-
------------------
34-
-1 day +02:03:00
32+
22 hours ago...
33+
-------------------
34+
-1 days +02:03:00
3535
(1 row)
3636

3737
SELECT INTERVAL '1.5 weeks' AS "Ten days twelve hours";
@@ -288,7 +288,7 @@ FROM INTERVAL_MULDIV_TBL;
288288
product
289289
------------------------------------
290290
1 year 12 days 122:24:00
291-
-1 year -12 days +93:36:00
291+
-1 years -12 days +93:36:00
292292
-3 days -14:24:00
293293
2 mons 13 days 01:22:28.8
294294
-10 mons +120 days 37:28:21.6567
@@ -317,7 +317,7 @@ FROM INTERVAL_MULDIV_TBL;
317317
----------------------------------
318318
4 mons 4 days 40:48:00
319319
-4 mons -4 days +31:12:00
320-
-1 day -04:48:00
320+
-1 days -04:48:00
321321
25 days -15:32:30.4
322322
-3 mons +30 days 12:29:27.2189
323323
12 days
@@ -785,9 +785,9 @@ SELECT interval '+1 -1:00:00',
785785
interval '-1 +1:00:00',
786786
interval '+1-2 -3 +4:05:06.789',
787787
interval '-1-2 +3 -4:05:06.789';
788-
interval | interval | interval | interval
789-
-----------------+------------------+-------------------------------------+---------------------------------------
790-
1 day -01:00:00 | -1 day +01:00:00 | 1 year 2 mons -3 days +04:05:06.789 | -1 year -2 mons +3 days -04:05:06.789
788+
interval | interval | interval | interval
789+
-----------------+-------------------+-------------------------------------+----------------------------------------
790+
1 day -01:00:00 | -1 days +01:00:00 | 1 year 2 mons -3 days +04:05:06.789 | -1 years -2 mons +3 days -04:05:06.789
791791
(1 row)
792792

793793
-- test output of couple non-standard interval values in the sql style

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