Re: Datum as struct

Peter Eisentraut <peter@eisentraut.org>

From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-08-05T18:06:26Z
Lists: pgsql-hackers
 > diff --git a/src/backend/utils/adt/timestamp.c 
b/src/backend/utils/adt/timestamp.c
 > index 25cff56c3d0..e640b48205b 100644
 > --- a/src/backend/utils/adt/timestamp.c
 > +++ b/src/backend/utils/adt/timestamp.c
 > @@ -4954,7 +4954,7 @@ timestamptz_trunc_internal(text *units, 
TimestampTz timestamp, pg_tz *tzp)
 >  				case DTK_SECOND:
 >  				case DTK_MILLISEC:
 >  				case DTK_MICROSEC:
 > -					PG_RETURN_TIMESTAMPTZ(timestamp);
 > +					return timestamp;
 > 					break;
 >
 > 				default:

This one is an actual bug.  With int64-pass-by-reference, 
PG_RETURN_TIMESTAMPTZ() returns a newly allocated address.  This is 
easily reproduced by

SELECT date_trunc( 'week', timestamp with time zone 'infinity' );

which will return a random value on 32-bit systems.  (It correctly 
returns 'infinity' otherwise.)

I'll see about backpatching fixes for this.





Commits

  1. Use consistent type for pgaio_io_get_id() result

  2. Mop-up for Datum conversion cleanups.

  3. Add missing Datum conversions

  4. Remove useless/superfluous Datum conversions

  5. Fix incorrect lack of Datum conversion in _int_matchsel()

  6. Improve tests of date_trunc() with infinity and unsupported units

  7. Fix incorrect Datum conversion in timestamptz_trunc_internal()

  8. Fix various hash function uses

  9. Fix mixups of FooGetDatum() vs. DatumGetFoo()