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

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

On Fri, Sep 9, 2016 at 8:02 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:

> 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
>

Understood. Just confused me for a while and wanted to make sure it wasn't
a real issue. Thanks!

Keith

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jürgen Strobel 2016-09-10 00:10:45 BUG #14321: pg_basebackup --xlog-method=stream fails
Previous Message Andres Freund 2016-09-10 00:02:04 Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()