Skip to content

Commit 5da9868

Browse files
committed
In messages, use singular nouns for -1, like we do for +1.
This outputs "-1 year", not "-1 years". Reported-by: neverov.max@gmail.com Bug: 16939 Discussion: https://postgr.es/m/16939-cceeb03fb72736ee@postgresql.org
1 parent 6131ffc commit 5da9868

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 2 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-
(value != 1) ? "s" : "");
4193+
(abs(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, (value == 1) ? "" : "s");
4219+
sprintf(cp, " %d %s%s", value, units, (abs(value) == 1) ? "" : "s");
42204220
*is_zero = false;
42214221
return cp + strlen(cp);
42224222
}

src/interfaces/ecpg/pgtypeslib/interval.c

Lines changed: 2 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, (value == 1) ? "" : "s");
697+
sprintf(cp, " %d %s%s", value, units, (abs(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-
(value != 1) ? "s" : "");
714+
(abs(value) != 1) ? "s" : "");
715715

716716
/*
717717
* Each nonzero field sets is_before for (only) the next one. This is a

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-
(PQntuples(res) == 1) ? "" : "s");
306+
(abs(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-
(PQntuples(res) == 1) ? "" : "s");
665+
(abs(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 days +02:03:00
26+
22 hours ago...
27+
------------------
28+
-1 day +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 days +02:03:00
32+
22 hours ago...
33+
------------------
34+
-1 day +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 years -12 days +93:36:00
291+
-1 year -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 days -04:48:00
320+
-1 day -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 days +01:00:00 | 1 year 2 mons -3 days +04:05:06.789 | -1 years -2 mons +3 days -04: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
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