Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str() - Mailing list pgsql-bugs

From Andres Freund
Subject Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()
Date
Msg-id 20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de
Whole thread Raw
In response to BUG #14322: Possible inconsistent behavior with timestamp_to_str()  (keith@keithf4.com)
Responses Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()  (Keith <keith@keithf4.com>)
List pgsql-bugs
On 2016-09-09 23:54:48 +0000, keith@keithf4.com wrote:
> The following bug has been logged on the website:
>
> Bug reference:      14322
> Logged by:          Keith Fiske
> Email address:      keith@keithf4.com
> PostgreSQL version: 9.5.4
> Operating system:   Ubuntu 16.04
> Description:
>
> It seems when I call timestamp_to_str() on a non-null value then call it on
> a null value in the same statement, it returns the previous non-null value.
> I've included the code and debug lines from where I encountered this when
> testing my app.

Uh. You can't just call timestamptz_to_str() on a NULL value. The datum
doesn't have to have any meaningful value if it's null.


> I know I should always check for a null return from SPI before operating on
> a value, and I do before I actually use those values. But I had them in my
> debug lines where checking for whether they're null before outputting to
> debug didn't seem to matter and it was really confusing me why the values
> were returning recent timestamp values when I was pretty sure they were
> null. Not sure if this can just be chalked up to undefined behavior when
> dealing with nulls or it's an actual problem, so figured I'd report it.

I don't think there's an issue here.  The datum value isn't guaranteed
to be initialized if the value is null, and I think that's what you're
seeing here.

Greetings,

Andres Freund

pgsql-bugs by date:

Previous
From: keith@keithf4.com
Date:
Subject: BUG #14322: Possible inconsistent behavior with timestamp_to_str()
Next
From: Keith
Date:
Subject: Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()