Skip to content

Commit c8c40bb

Browse files
committed
Cause the format of BC timestamptz output to be 'datetime zone BC' rather
than 'datetime BC zone', because the former is accepted by the timestamptz input converter while the latter may not be depending on spacing. This is not a loss of compatibility w.r.t. 7.4 and before, because until very recently there was never a case where we'd output both zone and 'BC'.
1 parent 59429ad commit c8c40bb

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.130 2004/06/03 02:08:04 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.131 2004/07/11 04:57:04 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3521,19 +3521,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
35213521
if (fsec != 0)
35223522
{
35233523
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
3524+
TrimTrailingZeros(str);
3525+
}
35243526
#else
35253527
if ((fsec != 0) && (tm->tm_year > 0))
35263528
{
35273529
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
3528-
#endif
35293530
TrimTrailingZeros(str);
35303531
}
3532+
#endif
35313533
else
35323534
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
35333535

3534-
if (tm->tm_year <= 0)
3535-
sprintf((str + strlen(str)), " BC");
3536-
35373536
/*
35383537
* tzp == NULL indicates that we don't want *any* time zone
35393538
* info in the output string. *tzn != NULL indicates that we
@@ -3546,6 +3545,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
35463545
min = ((abs(*tzp) / 60) % 60);
35473546
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
35483547
}
3548+
3549+
if (tm->tm_year <= 0)
3550+
sprintf((str + strlen(str)), " BC");
35493551
break;
35503552

35513553
case USE_SQL_DATES:
@@ -3571,19 +3573,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
35713573
if (fsec != 0)
35723574
{
35733575
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
3576+
TrimTrailingZeros(str);
3577+
}
35743578
#else
35753579
if ((fsec != 0) && (tm->tm_year > 0))
35763580
{
35773581
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
3578-
#endif
35793582
TrimTrailingZeros(str);
35803583
}
3584+
#endif
35813585
else
35823586
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
35833587

3584-
if (tm->tm_year <= 0)
3585-
sprintf((str + strlen(str)), " BC");
3586-
35873588
if ((tzp != NULL) && (tm->tm_isdst >= 0))
35883589
{
35893590
if (*tzn != NULL)
@@ -3595,6 +3596,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
35953596
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
35963597
}
35973598
}
3599+
3600+
if (tm->tm_year <= 0)
3601+
sprintf((str + strlen(str)), " BC");
35983602
break;
35993603

36003604
case USE_GERMAN_DATES:
@@ -3617,19 +3621,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
36173621
if (fsec != 0)
36183622
{
36193623
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
3624+
TrimTrailingZeros(str);
3625+
}
36203626
#else
36213627
if ((fsec != 0) && (tm->tm_year > 0))
36223628
{
36233629
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
3624-
#endif
36253630
TrimTrailingZeros(str);
36263631
}
3632+
#endif
36273633
else
36283634
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
36293635

3630-
if (tm->tm_year <= 0)
3631-
sprintf((str + strlen(str)), " BC");
3632-
36333636
if ((tzp != NULL) && (tm->tm_isdst >= 0))
36343637
{
36353638
if (*tzn != NULL)
@@ -3641,6 +3644,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
36413644
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
36423645
}
36433646
}
3647+
3648+
if (tm->tm_year <= 0)
3649+
sprintf((str + strlen(str)), " BC");
36443650
break;
36453651

36463652
case USE_POSTGRES_DATES:
@@ -3671,20 +3677,20 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
36713677
if (fsec != 0)
36723678
{
36733679
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
3680+
TrimTrailingZeros(str);
3681+
}
36743682
#else
36753683
if ((fsec != 0) && (tm->tm_year > 0))
36763684
{
36773685
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
3678-
#endif
36793686
TrimTrailingZeros(str);
36803687
}
3688+
#endif
36813689
else
36823690
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
36833691

36843692
sprintf((str + strlen(str)), " %04d",
36853693
((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)));
3686-
if (tm->tm_year <= 0)
3687-
sprintf((str + strlen(str)), " BC");
36883694

36893695
if ((tzp != NULL) && (tm->tm_isdst >= 0))
36903696
{
@@ -3704,11 +3710,14 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
37043710
sprintf((str + strlen(str)), ((min != 0) ? " %+03d:%02d" : " %+03d"), hour, min);
37053711
}
37063712
}
3713+
3714+
if (tm->tm_year <= 0)
3715+
sprintf((str + strlen(str)), " BC");
37073716
break;
37083717
}
37093718

37103719
return TRUE;
3711-
} /* EncodeDateTime() */
3720+
}
37123721

37133722

37143723
/* EncodeInterval()

src/test/regress/expected/horology.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL;
672672
| Sat Feb 14 17:32:01 1998 PST
673673
| Sun Feb 15 17:32:01 1998 PST
674674
| Mon Feb 16 17:32:01 1998 PST
675-
| Thu Feb 16 17:32:01 0096 BC PST
675+
| Thu Feb 16 17:32:01 0096 PST BC
676676
| Sun Feb 16 17:32:01 0098 PST
677677
| Fri Feb 16 17:32:01 0598 PST
678678
| Wed Feb 16 17:32:01 1098 PST
@@ -741,7 +741,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL;
741741
| Wed Feb 14 17:32:01 1996 PST
742742
| Thu Feb 15 17:32:01 1996 PST
743743
| Fri Feb 16 17:32:01 1996 PST
744-
| Mon Feb 16 17:32:01 0098 BC PST
744+
| Mon Feb 16 17:32:01 0098 PST BC
745745
| Thu Feb 16 17:32:01 0096 PST
746746
| Tue Feb 16 17:32:01 0596 PST
747747
| Sun Feb 16 17:32:01 1096 PST

src/test/regress/expected/timestamptz.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL;
180180
| Fri Feb 14 17:32:01 1997 PST
181181
| Sat Feb 15 17:32:01 1997 PST
182182
| Sun Feb 16 17:32:01 1997 PST
183-
| Tue Feb 16 17:32:01 0097 BC PST
183+
| Tue Feb 16 17:32:01 0097 PST BC
184184
| Sat Feb 16 17:32:01 0097 PST
185185
| Thu Feb 16 17:32:01 0597 PST
186186
| Tue Feb 16 17:32:01 1097 PST
@@ -266,7 +266,7 @@ SELECT '' AS "15", d1 FROM TIMESTAMPTZ_TBL
266266
----+---------------------------------
267267
| -infinity
268268
| Wed Dec 31 16:00:00 1969 PST
269-
| Tue Feb 16 17:32:01 0097 BC PST
269+
| Tue Feb 16 17:32:01 0097 PST BC
270270
| Sat Feb 16 17:32:01 0097 PST
271271
| Thu Feb 16 17:32:01 0597 PST
272272
| Tue Feb 16 17:32:01 1097 PST
@@ -332,7 +332,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMPTZ_TBL
332332
| Fri Feb 14 17:32:01 1997 PST
333333
| Sat Feb 15 17:32:01 1997 PST
334334
| Sun Feb 16 17:32:01 1997 PST
335-
| Tue Feb 16 17:32:01 0097 BC PST
335+
| Tue Feb 16 17:32:01 0097 PST BC
336336
| Sat Feb 16 17:32:01 0097 PST
337337
| Thu Feb 16 17:32:01 0597 PST
338338
| Tue Feb 16 17:32:01 1097 PST
@@ -364,7 +364,7 @@ SELECT '' AS "16", d1 FROM TIMESTAMPTZ_TBL
364364
| -infinity
365365
| Wed Dec 31 16:00:00 1969 PST
366366
| Thu Jan 02 00:00:00 1997 PST
367-
| Tue Feb 16 17:32:01 0097 BC PST
367+
| Tue Feb 16 17:32:01 0097 PST BC
368368
| Sat Feb 16 17:32:01 0097 PST
369369
| Thu Feb 16 17:32:01 0597 PST
370370
| Tue Feb 16 17:32:01 1097 PST

0 commit comments

Comments
 (0)