mirror of
https://github.com/postgres/postgres.git
synced 2025-06-07 11:02:12 +03:00
Revert use singular for -1 (commits 9ee7d533da and 5da9868ed9
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
This commit is contained in:
parent
e6f9539dc3
commit
651d005e76
@ -1100,8 +1100,8 @@ FROM dblink('myconn',
|
|||||||
'SELECT * FROM (VALUES (''-1 2:03:04'')) i')
|
'SELECT * FROM (VALUES (''-1 2:03:04'')) i')
|
||||||
AS i(i interval);
|
AS i(i interval);
|
||||||
i
|
i
|
||||||
------------------
|
-------------------
|
||||||
-1 day -02:03:04
|
-1 days -02:03:04
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- Try swapping to another format to ensure the GUCs are tracked
|
-- Try swapping to another format to ensure the GUCs are tracked
|
||||||
|
@ -4190,7 +4190,7 @@ AddPostgresIntPart(char *cp, int value, const char *units,
|
|||||||
(*is_before && value > 0) ? "+" : "",
|
(*is_before && value > 0) ? "+" : "",
|
||||||
value,
|
value,
|
||||||
units,
|
units,
|
||||||
(abs(value) != 1) ? "s" : "");
|
(value != 1) ? "s" : "");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each nonzero field sets is_before for (only) the next one. This is a
|
* 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)
|
else if (*is_before)
|
||||||
value = -value;
|
value = -value;
|
||||||
sprintf(cp, " %d %s%s", value, units, (abs(value) == 1) ? "" : "s");
|
sprintf(cp, " %d %s%s", value, units, (value == 1) ? "" : "s");
|
||||||
*is_zero = false;
|
*is_zero = false;
|
||||||
return cp + strlen(cp);
|
return cp + strlen(cp);
|
||||||
}
|
}
|
||||||
@ -4414,6 +4414,7 @@ EncodeInterval(struct pg_tm *tm, fsec_t fsec, int style, char *str)
|
|||||||
else if (is_before)
|
else if (is_before)
|
||||||
*cp++ = '-';
|
*cp++ = '-';
|
||||||
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, false);
|
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, false);
|
||||||
|
/* We output "ago", not negatives, so use abs(). */
|
||||||
sprintf(cp, " sec%s",
|
sprintf(cp, " sec%s",
|
||||||
(abs(sec) != 1 || fsec != 0) ? "s" : "");
|
(abs(sec) != 1 || fsec != 0) ? "s" : "");
|
||||||
is_zero = false;
|
is_zero = false;
|
||||||
|
@ -694,7 +694,7 @@ AddVerboseIntPart(char *cp, int value, const char *units,
|
|||||||
}
|
}
|
||||||
else if (*is_before)
|
else if (*is_before)
|
||||||
value = -value;
|
value = -value;
|
||||||
sprintf(cp, " %d %s%s", value, units, (abs(value) == 1) ? "" : "s");
|
sprintf(cp, " %d %s%s", value, units, (value == 1) ? "" : "s");
|
||||||
*is_zero = false;
|
*is_zero = false;
|
||||||
return cp + strlen(cp);
|
return cp + strlen(cp);
|
||||||
}
|
}
|
||||||
@ -711,7 +711,7 @@ AddPostgresIntPart(char *cp, int value, const char *units,
|
|||||||
(*is_before && value > 0) ? "+" : "",
|
(*is_before && value > 0) ? "+" : "",
|
||||||
value,
|
value,
|
||||||
units,
|
units,
|
||||||
(abs(value) != 1) ? "s" : "");
|
(value != 1) ? "s" : "");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each nonzero field sets is_before for (only) the next one. This is a
|
* 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)
|
|||||||
*cp++ = '-';
|
*cp++ = '-';
|
||||||
AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, false);
|
AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, false);
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
|
/* We output "ago", not negatives, so use abs(). */
|
||||||
sprintf(cp, " sec%s",
|
sprintf(cp, " sec%s",
|
||||||
(abs(sec) != 1 || fsec != 0) ? "s" : "");
|
(abs(sec) != 1 || fsec != 0) ? "s" : "");
|
||||||
is_zero = false;
|
is_zero = false;
|
||||||
|
@ -303,7 +303,7 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
|
|||||||
}
|
}
|
||||||
if (po->header && !po->html3)
|
if (po->header && !po->html3)
|
||||||
fprintf(fout, "(%d row%s)\n\n", PQntuples(res),
|
fprintf(fout, "(%d row%s)\n\n", PQntuples(res),
|
||||||
(abs(PQntuples(res)) == 1) ? "" : "s");
|
(PQntuples(res) == 1) ? "" : "s");
|
||||||
if (po->html3 && !po->expanded)
|
if (po->html3 && !po->expanded)
|
||||||
fputs("</table>\n", fout);
|
fputs("</table>\n", fout);
|
||||||
free(fieldMax);
|
free(fieldMax);
|
||||||
@ -662,7 +662,7 @@ PQdisplayTuples(const PGresult *res,
|
|||||||
|
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
fprintf(fp, "\nQuery returned %d row%s.\n", PQntuples(res),
|
fprintf(fp, "\nQuery returned %d row%s.\n", PQntuples(res),
|
||||||
(abs(PQntuples(res)) == 1) ? "" : "s");
|
(PQntuples(res) == 1) ? "" : "s");
|
||||||
|
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ SELECT INTERVAL '-08:00' AS "Eight hours";
|
|||||||
|
|
||||||
SELECT INTERVAL '-1 +02:03' AS "22 hours ago...";
|
SELECT INTERVAL '-1 +02:03' AS "22 hours ago...";
|
||||||
22 hours ago...
|
22 hours ago...
|
||||||
------------------
|
-------------------
|
||||||
-1 day +02:03:00
|
-1 days +02:03:00
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT INTERVAL '-1 days +02:03' AS "22 hours ago...";
|
SELECT INTERVAL '-1 days +02:03' AS "22 hours ago...";
|
||||||
22 hours ago...
|
22 hours ago...
|
||||||
------------------
|
-------------------
|
||||||
-1 day +02:03:00
|
-1 days +02:03:00
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT INTERVAL '1.5 weeks' AS "Ten days twelve hours";
|
SELECT INTERVAL '1.5 weeks' AS "Ten days twelve hours";
|
||||||
@ -288,7 +288,7 @@ FROM INTERVAL_MULDIV_TBL;
|
|||||||
product
|
product
|
||||||
------------------------------------
|
------------------------------------
|
||||||
1 year 12 days 122:24:00
|
1 year 12 days 122:24:00
|
||||||
-1 year -12 days +93:36:00
|
-1 years -12 days +93:36:00
|
||||||
-3 days -14:24:00
|
-3 days -14:24:00
|
||||||
2 mons 13 days 01:22:28.8
|
2 mons 13 days 01:22:28.8
|
||||||
-10 mons +120 days 37:28:21.6567
|
-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 40:48:00
|
||||||
-4 mons -4 days +31:12:00
|
-4 mons -4 days +31:12:00
|
||||||
-1 day -04:48:00
|
-1 days -04:48:00
|
||||||
25 days -15:32:30.4
|
25 days -15:32:30.4
|
||||||
-3 mons +30 days 12:29:27.2189
|
-3 mons +30 days 12:29:27.2189
|
||||||
12 days
|
12 days
|
||||||
@ -786,8 +786,8 @@ SELECT interval '+1 -1:00:00',
|
|||||||
interval '+1-2 -3 +4:05:06.789',
|
interval '+1-2 -3 +4:05:06.789',
|
||||||
interval '-1-2 +3 -4:05:06.789';
|
interval '-1-2 +3 -4:05:06.789';
|
||||||
interval | interval | interval | interval
|
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 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
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- test output of couple non-standard interval values in the sql style
|
-- test output of couple non-standard interval values in the sql style
|
||||||
|
Loading…
x
Reference in New Issue
Block a user