Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()

From: Andres Freund <andres(at)anarazel(dot)de>
To: keith(at)keithf4(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()
Date: 2016-09-10 00:02:04
Message-ID: 20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2016-09-09 23:54:48 +0000, keith(at)keithf4(dot)com wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14322
> Logged by: Keith Fiske
> Email address: keith(at)keithf4(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Keith 2016-09-10 00:02:56 Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()
Previous Message keith 2016-09-09 23:54:48 BUG #14322: Possible inconsistent behavior with timestamp_to_str()