In messages, use singular nouns for -1, like we do for +1.
authorBruce Momjian <[email protected]>
Tue, 30 Mar 2021 22:34:27 +0000 (18:34 -0400)
committerBruce Momjian <[email protected]>
Tue, 30 Mar 2021 22:34:27 +0000 (18:34 -0400)
This outputs "-1 year", not "-1 years".

Reported-by: [email protected]
Bug: 16939

Discussion: https://postgr.es/m/16939-cceeb03fb72736ee@postgresql.org

src/backend/utils/adt/datetime.c
src/interfaces/ecpg/pgtypeslib/interval.c
src/interfaces/libpq/fe-print.c
src/test/regress/expected/interval.out

index 350b0c55eac529ac224d655742ff86a3cf1e931a..889077f55c558c0d236dd4b036d565de5c54c68b 100644 (file)
@@ -4190,7 +4190,7 @@ AddPostgresIntPart(char *cp, int value, const char *units,
            (*is_before && value > 0) ? "+" : "",
            value,
            units,
-           (value != 1) ? "s" : "");
+           (abs(value) != 1) ? "s" : "");
 
    /*
     * 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,
    }
    else if (*is_before)
        value = -value;
-   sprintf(cp, " %d %s%s", value, units, (value == 1) ? "" : "s");
+   sprintf(cp, " %d %s%s", value, units, (abs(value) == 1) ? "" : "s");
    *is_zero = false;
    return cp + strlen(cp);
 }
index 48ba50bbce3547382444572b07622ef3f01b1a7f..82196dfe80af7884de8e0b9bb6a604840a115e1d 100644 (file)
@@ -694,7 +694,7 @@ AddVerboseIntPart(char *cp, int value, const char *units,
    }
    else if (*is_before)
        value = -value;
-   sprintf(cp, " %d %s%s", value, units, (value == 1) ? "" : "s");
+   sprintf(cp, " %d %s%s", value, units, (abs(value) == 1) ? "" : "s");
    *is_zero = false;
    return cp + strlen(cp);
 }
@@ -711,7 +711,7 @@ AddPostgresIntPart(char *cp, int value, const char *units,
            (*is_before && value > 0) ? "+" : "",
            value,
            units,
-           (value != 1) ? "s" : "");
+           (abs(value) != 1) ? "s" : "");
 
    /*
     * Each nonzero field sets is_before for (only) the next one.  This is a
index 94219b1825bcbcabeee342f99c318aa1bf89210d..af19b3c0a3e355d4ee0ecd1ab5b69e3bf1b15ae7 100644 (file)
@@ -303,7 +303,7 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
        }
        if (po->header && !po->html3)
            fprintf(fout, "(%d row%s)\n\n", PQntuples(res),
-                   (PQntuples(res) == 1) ? "" : "s");
+                   (abs(PQntuples(res)) == 1) ? "" : "s");
        if (po->html3 && !po->expanded)
            fputs("</table>\n", fout);
        free(fieldMax);
@@ -662,7 +662,7 @@ PQdisplayTuples(const PGresult *res,
 
    if (!quiet)
        fprintf(fp, "\nQuery returned %d row%s.\n", PQntuples(res),
-               (PQntuples(res) == 1) ? "" : "s");
+               (abs(PQntuples(res)) == 1) ? "" : "s");
 
    fflush(fp);
 
index acc353a0dc36c02fcddfb348f9346e68d71b394b..c5ffa9f2cc1295c899a335e2b096dcbc8fce5055 100644 (file)
@@ -23,15 +23,15 @@ SELECT INTERVAL '-08:00' AS "Eight hours";
 (1 row)
 
 SELECT INTERVAL '-1 +02:03' AS "22 hours ago...";
 22 hours ago...  
--------------------
- -1 days +02:03:00
+ 22 hours ago...  
+------------------
+ -1 day +02:03:00
 (1 row)
 
 SELECT INTERVAL '-1 days +02:03' AS "22 hours ago...";
 22 hours ago...  
--------------------
- -1 days +02:03:00
+ 22 hours ago...  
+------------------
+ -1 day +02:03:00
 (1 row)
 
 SELECT INTERVAL '1.5 weeks' AS "Ten days twelve hours";
@@ -288,7 +288,7 @@ FROM INTERVAL_MULDIV_TBL;
               product               
 ------------------------------------
  1 year 12 days 122:24:00
- -1 years -12 days +93:36:00
+ -1 year -12 days +93:36:00
  -3 days -14:24:00
  2 mons 13 days 01:22:28.8
  -10 mons +120 days 37:28:21.6567
@@ -317,7 +317,7 @@ FROM INTERVAL_MULDIV_TBL;
 ----------------------------------
  4 mons 4 days 40:48:00
  -4 mons -4 days +31:12:00
- -1 days -04:48:00
+ -1 day -04:48:00
  25 days -15:32:30.4
  -3 mons +30 days 12:29:27.2189
  12 days
@@ -785,9 +785,9 @@ SELECT  interval '+1 -1:00:00',
         interval '-1 +1:00:00',
         interval '+1-2 -3 +4:05:06.789',
         interval '-1-2 +3 -4:05:06.789';
-    interval     |     interval      |              interval               |                interval                
------------------+-------------------+-------------------------------------+----------------------------------------
- 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
+    interval     |     interval     |              interval               |               interval                
+-----------------+------------------+-------------------------------------+---------------------------------------
+ 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
 (1 row)
 
 -- test output of couple non-standard interval values in the sql style