pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: keith@keithf4.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()
Date: Fri, 9 Sep 2016 17:02:04 -0700
Message-ID: <20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de> (raw)
In-Reply-To: <20160909235448.20021.79001@wrigleys.postgresql.org>
References: <20160909235448.20021.79001@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (10+ messages)  latest in thread

Message-ID: <20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de>
Permalink:  ../20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andres@anarazel.de, keith@keithf4.com
  Subject: Re: BUG #14322: Possible inconsistent behavior with timestamp_to_str()
  In-Reply-To: <20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de>
  References: <20160909235448.20021.79001@wrigleys.postgresql.org> <20160910000204.mbbfdxtw4t4oelzs@alap3.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox